Equal Distinct Codechef Solution

Hello coders, today we are going to solve the Equal Distinct Codechef Solution whose Problem Code is EQDIS.

Problem

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).

Input Format

• 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 NN space-separated integer A1​, A2​, …, AN​, 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 `yEs``yes``Yes`, and `YES` will all be treated as identical).

Input

```3
2
1 2
3
1 2 3
4
3 1 1 2```

YES
NO
YES

Explanation:

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.

Equal Distinct Codechef Solution in CPP

```#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
ll n;
cin>>n;
vector<ll> v(n);
for(ll i=0;i<n;i++){
cin>>v[i];
}
map<ll,ll> mp;
for(auto &it:v)mp[it]++;
ll count=0;
for(auto &it:mp){
if(it.second==1)count++;
}
if((n%2==1 && count==n))cout<<"no"<<endl;
else cout<<"yes"<<endl;
}
int main() {
ll t;
cin>>t;
while(t--){
solve();
}
return 0;
}
```

Equal Distinct Codechef Solution in JAVA

```/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0)
{
int n=sc.nextInt();
HashSet<Integer> h1=new HashSet<Integer>();
for(int i=0;i<n;i++)
{
int x=sc.nextInt();
}
if(n==h1.size() && n%2!=0)
System.out.println("No");
else
System.out.println("Yes");
}
}
}
```

Equal Distinct Codechef Solution in Python

```# Chase2learn
t = int(input())
for i in range(t):
n = int(input())
arr = [int(i) for i in input().split()]
ass = set(arr)
if n%2 == 0:
print("YES")
else:
if len(arr) == len(ass):
print("NO")
else:
print("YES")
```

Disclaimer: The above Problem (Equal Distinct) is generated by CodeChef but the solution is provided by Chase2learn.This tutorial is only for Educational and Learning purpose.

Sharing Is Caring