Data Structures & AlgorithmsHardICPC regional · Amazon SDE OA

Given an array of 10^6 values and window size k, you need the maximum over all windows of the window minimum. What is the most suitable approach?

  1. A. A segment tree built per window, giving O(n k log n)
  2. B. Sorting each window separately, giving O(n k log k)
  3. C. A monotonic deque for sliding-window minima, giving O(n) total time
  4. D. Brute-force scanning with a priority queue of all windows, giving O(n^2)

Correct answer: C. A monotonic deque for sliding-window minima, giving O(n) total time

The deque keeps candidates in increasing order and expires indices outside the window, so each element enters and leaves once. The other choices do much more work per window.

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

Exams that ask this topic