Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA

How many windows of size 3 in [1, 3, 2, 6, 4, 5, 1] have max minus min at most 2?

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

Correct answer: C. 2

A pair of monotonic deques gives each window's max and min in O(1) amortised. The check uses an inclusive bound, so a spread exactly 2 counts.

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

Exams that ask this topic