Largest XOR sum subarray
InterviewTime limit10sMemory limit512 MB
Given a sequence, find the maximum XOR value over all contiguous subarrays of length at least one.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Trie, Prefix sum, Array
- Solved
- No attempts yet
Problem
You are given a sequence of numbers. Pick one contiguous subarray of it. The XOR sum of a subarray is the value you get by XOR-ing every element in that subarray.
Given , write a program that finds the largest XOR sum over all contiguous subarrays of length at least 1.
Input
The first line contains the number of test cases . ()
Each test case takes two lines. The first line contains the size of the sequence (), and the second line contains the elements of separated by spaces. Each element is a non-negative integer that fits in a 32-bit signed integer, so it is an integer between and .
Output
For each test case, print the largest XOR sum over the contiguous subarrays of on its own line.