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.