0% found this document useful (0 votes)
20 views1 page

Input: N (Size of The Array) - The Next N Lines of Each Test-Case Contain Integers Denoting The Elements of The

Given an array of numbers, the task is to find a contiguous subsequence whose elements have the maximum bitwise XOR sum. The input consists of the number of test cases, each containing the size of the array and its elements. For each test case, output the maximum XOR sum of a subsequence.

Uploaded by

Navpreet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views1 page

Input: N (Size of The Array) - The Next N Lines of Each Test-Case Contain Integers Denoting The Elements of The

Given an array of numbers, the task is to find a contiguous subsequence whose elements have the maximum bitwise XOR sum. The input consists of the number of test cases, each containing the size of the array and its elements. For each test case, output the maximum XOR sum of a subsequence.

Uploaded by

Navpreet Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Given an array of N numbers, we wish to choose a contiguous sub-sequence of the array, so that the

bitwise XOR of all chosen numbers is maximum. Bitwise XOR is defined as follows: every bit in the
answer is obtained by applying XOR logic on the corresponding bits of the set of numbers. For example
7, 8 and 5 are XORed as follows,

Numbers in binary: 0111 1000 0101 ----- 1010


So the answer is 10 (in decimal). The same answer can be obtained in C/C++/Java by using the
XOR operator as 7ˆ8ˆ5.

Input
The first line contains the number of test cases T . The first line of each test-case contains one integer,
N (size of the array). The next N lines of each test-case contain integers denoting the elements of the
array.

Output
For each test case, output a single line containing the maximum sum that can be obtained.
Constraints:
• 1 ≤ T ≤ 10
• 1 ≤ N ≤ 100, 000

• All input integers will be non-negative and fit into 32 bit signed integer.

Sample Input
2 5 3 7 7 7 0 5 3 8 2 6 4

Sample Output
7 15

You might also like