Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 B

Which structure returns the maximum of every window of size k in a sliding pass in O(n) total time?

  1. A. Binary heap of all window elements
  2. B. Sorted array with insertion
  3. C. Monotonic deque
  4. D. Hash map of window counts

Correct answer: C. Monotonic deque

A deque keeps indices in decreasing value order; the front is the window maximum and each index enters and leaves at most once.

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

Exams that ask this topic