Data Structures & AlgorithmsHard

How many contiguous subarrays of 2 9 4 7 1 8 3 have their MAXIMUM value located at an EVEN absolute index of the original array (index 0 counts as even)? If the maximum value appears more than once, use its first occurrence in the subarray.

  1. A. 24
  2. B. 16
  3. C. 17
  4. D. 4

Correct answer: D. 4

Locate the maximum of each subarray, converting its relative position into an absolute index before testing parity. Testing only the relative position, or flipping the parity, is a common slip.

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

Exams that ask this topic