A XOR value
Practice
3.2 (17 votes)
Algorithms
Basics of greedy algorithms
C++
Greedy algorithms
Problem
72% Success 4267 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given an array \(A\) consisting of \(N\) integer values. Find an integer \(K\) such that the value of the following function is minimized:

  • \(\sum_{i = 1}^{i = N} (A[i] \ XOR \ K)\) , \(XOR\) represents a bitwise XOR operation

If multiple such \(K\) exist, then print the minimum possible value of \(K\).

Input format

  • The first line contains an integer \(T\) denoting the number of test cases. For each test case:
  • The first line of each test case contains an integer \(N\).
  • The second line of each test case contains \(N\) space-separated integers denoting array \(A\).

Output format

For each test case, print the value of \(K\) in a new line.

Constraints 

\(1 \le T \le 10 \\ 1 \le N \le 10^5 \\ 1 \le A[i] \le 10^{18}\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
23 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms
Points:30
78 votes
Tags:
ApprovedEasyGreedy AlgorithmsMathOpen
Points:30
10 votes
Tags:
SortingAlgorithmsBasics of Greedy AlgorithmsGreedy Algorithms