Equal Distinct Codechef Solution

Hello Programmers In this post, you will know how to solve the Equal Distinct Codechef Solution. The Problem Code is EQDIS.

Equal Distinct Codechef Solution
Equal Distinct Codechef Solution

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Codechef by yourself. If you find any difficulty after trying several times, then you can look for solutions.

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 yEsyesYes, and YES will all be treated as identical).

Constraints

Equal Distinct Codechef Solution

Sample 1

Input

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

Output

YES
NO
YES

LinkedIn Skill Assessment Answers

Coursera Quiz Answers

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 Solutions 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
	{
		// your code goes here
	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();
				h1.add(x);
			}
			if(n==h1.size() && n%2!=0)
				System.out.println("No");
			else
				System.out.println("Yes");
		}
	}
}
Ezoicreport this ad

Equal Distinct Codechef Solution in Python

# Chase2learn
# cook your dish here
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 BrokenProgrammers. This tutorial is only for Educational and Learning purpose.

Note:- I compile all programs, if there is any case program is not working and showing an error please let me know in the comment section. If you are using adblocker, please disable adblocker because some functions of the site may not work correctly.

Next: Odd Pairs Codechef Solution

Sharing Is Caring

Leave a Comment