Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

How many windows of size 4 in the array [4, 2, 12, 3, 8, 1, 9, 5] have their maximum at the first position of the window (ties with a later element allowed)?

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

Correct answer: C. 1

For each window, check whether its first element is at least every other element in it. A monotonic deque shows which windows qualify in linear time.

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

Exams that ask this topic