[6, 3, 5] → [5, 6] → [3], so the result is 3. A block of one number folds to itself.
You get an array values and a list of queries ranges, where ranges[i] = [l, r]. For each query, find the largest fold result over all contiguous blocks lying entirely inside values[l..r] (inclusive).
Return the answers in query order.values=[6, 3, 5], ranges=[[0, 1], [0, 2], [2, 2]] → [6, 6, 5]
In range [0, 1] the blocks [6], [3] and [6, 3] give 6, 3 and 6 XOR 3 = 5, so the best is 6. The whole array [6, 3, 5] folds to [5, 6] and then to 3, while [3, 5] gives 6, so the best is again 6. Range [2, 2] is just the number 5.
values=[1, 2, 4, 8], ranges=[[0, 3], [1, 2]] → [15, 6]
The whole array folds as [1, 2, 4, 8] → [3, 6, 12] → [5, 10] → [15], and 15 is the best result for the first query. In the second query the block [2, 4] gives 6.
values=[6, 3, 5], ranges=[[0, 1], [0, 2], [2, 2]]
[6, 6, 5]
Run checks the first 3 tests in your browser. Submit checks all 57 tests on the server, hidden ones included.