# MEX problem

Can anybody please guide me to solve the below question:

Problem Statement:
You are given an array A consisting of N integers.

Determine the maximum possible MEX of sequence B where the ith element Bi = (Ai xor C), where C is any constant non-negative integer.

Note: Mex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as an element. For example, MEX([4,0,1,1]) = 2 and MEX([1,2])=0

Example:
Input : N = 4 , A = [2,3,4,5]
Output : 2

Explanation:

• Taking the value of C=1, the obtained sequence becomes B=[3,2,5,4]. Here the MEX of the sequence is 0.
• Taking the value of C=2, the obtained sequence becomes B=[0,1,6,7]. Here the MEX of the sequence is 2.
• Taking the value of C=3, the obtained sequence becomes B=[1,0,7,6]. Here the MEX of the sequence is 2.
• Taking the value of C=4, the obtained sequence becomes B=[1,0,7,6]. Here the MEX of the sequence is 2.
• Similarly, you can calculate MEX for other C as well.
• The maximum MEX you can get from all the sequences is 2 from the sequence where C=[2,3,4,… etc] as the numbers 0 and 1 are present in this sequence.

Once you obtained array B, just sort it.
Now check from i=0 to i= n-1 , if B[i]!= i, then ‘i’ is the correct answer.
else ‘n’ is the answer.

Can you tell the constraints of the problem?

Hi Sir,
Thanks for your response.
I am a newbie in this. If possible could you please elaborate more on this?

Below are the constraints.
1<= T <=10
1<=N<=10^5
1<=Ai<=10^9