Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

Over all windows of size 3 in [4, 8, 2, 7, 5, 9], what is the smallest value of (window max minus window min)?

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

Correct answer: C. 4

Two monotonic deques give each window's maximum and minimum in amortised O(1). The window [7, 5, 9] has spread 4, which is the smallest here.

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

Exams that ask this topic