Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

Array A = [9, 3, 7, 1, 7, 4, 3]. Over all non-empty contiguous subarrays, what is the maximum value of the XOR of the elements in the subarray?

  1. A. 34
  2. B. 15
  3. C. 9
  4. D. 14

Correct answer: B. 15

XOR over a subarray is a prefix-XOR difference, so the best subarray XOR is 15. Kadane's sum, the single largest element, or XOR of arbitrary (non-contiguous) pairs answer different questions.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic