Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

How many elements of the array [3, 1, 4, 1, 5, 9, 2, 6] have no strictly greater element anywhere to their right?

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

Correct answer: C. 2

Scan from the right while keeping the running maximum; an element is counted when it is at least as large as everything after it, which is what a monotonic stack detects.

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

Exams that ask this topic