304 North Cardinal St.
Dorchester Center, MA 02124

# Equal MEX CodeChef Solution

## Equal MEX CodeChef Solution in C++17

``````#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t--) {
int n;
cin>>n;
int tmp;
vector<int>occ(n+1,0);
for(int i=0; i<2*n; i++) {
cin>>tmp;
occ[tmp]++;
}

int smallest = n+1;
for(int i=0; i<=n; i++) {
if(occ[i] == 0) {
smallest = i;
break;
}
}

if(smallest == n+1) {
cout<<"NO\n";
continue;
}

bool ans = true;
for(int i=0; i<smallest; i++) {
if(occ[i]<2) {
ans = false;
break;
}
}

if(ans) cout<<"YES\n";
else cout<<"NO\n";

}
return 0;
}``````

## Equal MEX CodeChef Solution in C++14

``````#include <bits/stdc++.h>
using namespace std;

int main() {
int T;
cin>>T;
while(T--)
{
int N;
cin>>N;
int A[2*N];
map<int,int>mp;
for(int i = 0; i < 2*N; i++)
{
cin>>A[i];
mp[A[i]]++;
}
int i=0;
bool flag = 1;
for(auto it : mp)
{
if(it.first==i)
{
if(it.second<2)
{
flag = 0;
break;
}
}
i++;
}
(flag) ? cout<<"YES" : cout<<"NO";
cout<<endl;
}
return 0;
}``````

## Equal MEX CodeChef Solution in PYTH 3

``````# cook your dish here
from collections import defaultdict
for _ in range(int(input())):
N = (2*int(input()))
A = sorted(list(map(int, input().split()))); cnt = i = 0
while i < N:
cn = 0
while i < N and A[i] == cnt:
cn += 1
i += 1
if cn == 1: print("NO"); break
if cn == 0: print("YES"); break
cnt += 1
else:
print("YES")
``````

## Equal MEX CodeChef Solution in C

``````#include <stdio.h>

int main()
{
long long int T,i,N,j,C,k;
scanf("%lld",&T);
for(i=0;i<T;i++){
scanf("%lld",&N);
long long int A[N+1];
for(j=0;j<=N;j++){
A[j]=0;
}
for(j=0;j<2*N;j++){
scanf("%lld",&C);
A[C]=A[C]+1;
}
for(k=0,j=0;j<=N;j++){
if(A[j]==0){
break;
}
else if(A[j]==1){
k=1;
break;
}
}
(k==0)?(printf("YES\n")):(printf("NO\n"));
}
return 0;
}
``````

## Equal MEX 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 int solve(){
int res=0;

return res;
}
public static void main (String[] args) throws java.lang.Exception
{
PrintWriter out = new PrintWriter(System.out);
Scanner sc = new Scanner(System.in);
int testCases = sc.nextInt();
while(testCases-->0){
int n = sc.nextInt();
TreeMap<Integer,Integer> map = new TreeMap<>();
for(int i=0;i<2*n;i++){
int x = sc.nextInt();
map.put(x,map.getOrDefault(x,0)+1);
}
boolean ans = true;
int st = 0;
for(int key : map.keySet()){
if(key != st++) break;
int x = map.get(key);
if(x == 1) {
ans = false;
break;
}
}
if(ans) out.println("YES");
else out.println("NO");

}
out.close();
}
}``````

## Equal MEX CodeChef Solution in PYPY 3

``````testcases = int(input())
for eachcase in range(testcases):
length = int(input())
array = list(map(int, input().split()))

hashmap = {}
for nums in array:
hashmap[nums] = 1 + hashmap.get(nums, 0)

currmin = min(array)
if currmin == 0:
while True:
count = hashmap.get(currmin, 0)
if count == 0:
print("YES")
break
if count < 2:
print("NO")
break
currmin += 1
else:
print("YES")``````

## Equal MEX CodeChef Solution in PYTH

``````t = int(raw_input())
for i in range(t):
N = int(raw_input())
st = raw_input().split()
A = []
for x in st:
A.append(int(x))
# endfor x
A.sort()
A.append(10**6)
found = True
cnt = 1
n = 0
p = 0
while found and (cnt > 0):
cnt = 0
while A[p] == n:
cnt += 1
p += 1
# endwhile
if cnt == 1:
found = False
# endif
n += 1
# endwhile
if found:
print 'YES'
else:
print 'NO'
# endif
# endfor i
``````

## Equal MEX CodeChef Solution in C#

``````using System;

class Program
{
void Solve()
{
int[] v = new int[2*n];
for(int i=0;i<n*2;i++)
{
v[i]=int.Parse(nr[i]);
}
Array.Sort(v);
int mex=0;
int freq=0;
for(int i=0;i<n*2;i++)
{
if(v[i]==mex)
{
freq++;
if(freq==2)
{
freq=0;
mex++;
}
}
}
if(freq==0)Console.WriteLine("YES");
else Console.WriteLine("NO");
}
static void Main()
{
while(t>0)
{
t--;
new Program().Solve();
}
}
}``````

## Equal MEX CodeChef Solution in NODEJS

``````"use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});

process.stdin.on("end", (_) => {
inputString = inputString
.trim()
.split("\n")
.map((string) => {
return string.trim();
});

main();
});

return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {

while(T--){
let arr = readline().split(" ").map(s => parseInt(s, 10));
const has = {}
for(let i=0; i < arr.length; i++){
if (has[arr[i]]) {
has[arr[i]]+=1
} else {
has[arr[i]] = 1
}
}

for(let i=0; i<=n; i++){
if (!has[i]) {
console.log("YES");
break;
} else {
if(has[i] == 1) {
console.log("NO");
break
}
}
}
//console.log(has);
}
return 0;
}``````

## Equal MEX CodeChef Solution in GO

``````package main

import (
"bufio"
"bytes"
"fmt"
"os"
"sort"
)

func main() {

var buf bytes.Buffer
for tc > 0 {
tc--
res := solve(arr)
if res {
buf.WriteString("YES\n")
} else {
buf.WriteString("NO\n")
}
}
fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}

for i := 0; i < len(s); i++ {
if s[i] == '\n' {
return s[:i]
}
}
return s
}

return
}

a, b = res[0], res[1]
return
}

a, b, c = res[0], res[1], res[2]
return
}

res := make([]int, n)
x := 0
for i := 0; i < n; i++ {
for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
x++
}
}
return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
i := from

var tmp uint64
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp

return i
}

func solve(arr []int) bool {
// n := len(arr) / 2
sort.Ints(arr)
// first no existing number or single number is the mex
var mex int
var i int
for i < len(arr) {
if arr[i] > mex {
return true
}
j := i
for i < len(arr) && arr[i] == arr[j] {
i++
}
if i-j == 1 {
return false
}
mex++
}
return true
}``````
##### Equal MEX CodeChef Solution Review:

In our experience, we suggest you solve this Equal MEX CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Equal MEX CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this Equal MEX CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!