Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

How many subarrays of [2, 5, 1, 5, 3] have a maximum value that occurs exactly once inside the subarray?

  1. A. 15
  2. B. 11
  3. C. 4
  4. D. 5

Correct answer: B. 11

Of the 15 subarrays, only those holding both 5s with nothing larger fail: [5,1,5], [2,5,1,5], [5,1,5,3], [2,5,1,5,3], so 11. 15 counts all subarrays, 4 counts the failing ones and 5 only the single elements.

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

Exams that ask this topic