[Solution] Equal Distinct solution codechef

Table of Contents

Equal Distinct solution codechef

Equal Distinct solution codechef – Let F(S) denote the number of distinct elements in the array S. For example, F([1, 2, 3, 2]) = 3, F([1, 2]) = 2.

You are given an array A containing N integers. Find if it is possible to divide the elements of the array A into two arrays B and C such that :

  • Every element of the array A belongs either to array B or to array C.
  • F(B) = F(C).

Equal Distinct solution codechef

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of two lines of input.
    • The first line of each test case contains an integer N — the length of the array A.
    • The next line contains N space-separated integer A_1, A_2, \dots, A_N, denoting the elements of the array A.

Output Format

For each test case, print YES if it is possible to divide the elements of the array A into two arrays B, C satisfying all the conditions and NO otherwise.

You may print each character of the string in either uppercase or lowercase (for example, the strings yEsyesYes, and YES will all be treated as identical).

Equal Distinct solution codechef

  • 1 \leq T \leq 10^4
  • 2 \leq N \leq 10^5
  • 1 \leq A_i \leq N
  • The sum of N over all test cases won’t exceed 2\cdot 10^5.

Sample 1:



1 2
1 2 3
3 1 1 2

Equal Distinct solution codechef

Test case 1: One possible division is B = [1], C = [2]. Here F(B) = F(C) = 1.

Test case 2: There is no way to distribute the elements of the array A = [1, 2, 3] satisfying all the conditions.

Test case 3: One possible division is B = [3, 1], C = [1, 2]. Here F(B) = F(C) = 2.

For Solution

“Click Here”

Leave a Comment