Data Structures & AlgorithmsHard

How many contiguous subarrays of 1 2 3 1 2 1 4 have the sum of their elements at EVEN relative positions equal to the sum at ODD relative positions (positions counted from the subarray's own start)?

  1. A. 12
  2. B. 0
  3. C. 3
  4. D. 2

Correct answer: D. 2

Relative positions restart at each subarray's start, so the test is on the subarray's own even and odd positions. Parity of the total sum or the even-length restriction changes which blocks qualify.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic