Maximum OR Minimum CodeChef Solution | CodeChef Problem Solution 2022
Alice and Bob are ready to play a new game. Both the players take alternate turns. Alice starts first.
There are binary numbers written on a blackboard.
- Alice, in her turn, erases any numbers from the blackboard and writes the bitwise OR of those numbers on the blackboard.
- Bob, in his turn, erases any numbers from the blackboard and writes the bitwise AND of those numbers on the blackboard.
Note that, after each move, the count of numbers written on the blackboard reduces by .
Both players play until a single number remains on the blackboard. Alice wants to maximise the remaining number while Bob wants to minimise the remaining number. Find the remaining number if both the players play optimally.
Input Format
- First line will contain , number of test cases. Then the test cases follow.
- First line of each test case contains of a single integer - the count of numbers written on the blackboard initially.
- Second line of each test case contains space-separated integers - the numbers written on the blackboard.
Output Format
For each test case, output in a single line, the remaining number, if both the players play optimally.
Constraints
- Sum of over all test cases does not exceed .
Sample Input 1
3
5
1 1 1 1 0
3
0 1 0
4
0 0 0 0
Sample Output 1
1
0
0
Explanation
Test case : Alice starts first.
- In the first move, Alice erases and and writes on the blackboard. Thus, after this move, the numbers written are .
- In the second move, Bob erases and and writes on the blackboard. Thus, after this move, the numbers written are .
- In the third move, Alice erases and and writes on the blackboard. Thus, after this move, the numbers written are .
- In the fourth move, Bob erases and and writes on the blackboard. Thus, after this move, the numbers written are .
Thus, the remaining number is .
Test case : It does not matter which two numbers Alice chooses. After the first move, the numbers on the blackboard would be . Thus, Bob erases these two numbers and writes .
Test case : In all the moves, both players erase two and write a single . Thus, the remaining element is .
Join Now for Solution:-
No comments:
Post a Comment