Hello Programmers In this post, you will know how to solve the Chef and Distinct Numbers 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
Given an array AA of size NN , check if there exist any pair of index i,ji,j such that Ai=AjAi=Aj and i≠ji≠j
Input
- The first line of the input contains a single integer TT denoting the number of test cases.
- The first line of each test case contains integer NN.
- The second line of each test case contains NN space separated integers AiAi.
Output
For each test case, print a single line containing answer “Yes” or “No” (without quotes).
Constraints
- 1≤T≤1001≤T≤100
- 2≤N≤1052≤N≤105
- 1≤Ai≤1091≤Ai≤109
- Sum of NN over all test cases doesn’t exceed 106106
Example Input
2 4 1 2 1 3 5 5 4 1 2 3
Example Output
Yes No
Explanation
Example case 1: A1A1 and A3A3 both have value 1.
Example case 2: All values are pairwise distinct.
Chef and Distinct Numbers CodeChef Solutions in JAVA
import java.util.Scanner; import java.util.Set; import java.util.HashSet; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int test = sc.nextInt(); while(test-- > 0) { int n = sc.nextInt(); int[] arr = new int[n]; for(int i = 0; i < n; i++) { arr[i] = sc.nextInt(); } Set<Integer> set = new HashSet<>(); for (int i = 0; i < n; i++) { set.add(arr[i]); } if (set.size() == n) System.out.println("No"); else System.out.println("Yes"); } } }
Chef and Distinct Numbers CodeChef Solutions in CPP
#include <iostream> #include<algorithm> using namespace std; int main() { int t; cin>>t; while(t--){ int n; cin>>n; long long int arr[n]; int i=0; while(n--){ cin>>arr[i]; i++; } int k=sizeof(arr)/sizeof(arr[0]); sort(arr,arr+k); int flag=0; for(int i=0;i<k;i++){ if(arr[i]==arr[i-1]){ cout<<"Yes"<<endl; flag=1; break; } } if(flag==0){ cout<<"No"<<endl; } } return 0; }
Chef and Distinct Numbers CodeChef Solutions in Python
cases=int(input()) for i in range(cases): n=int(input()) A=list(map(int,input().split())) A.sort() B=set(A) if len(A)==len(B): print("No") else: print("Yes")
Disclaimer: The above Problem (Chef and Distinct Numbers) 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: SmartPhone CodeChef Solution