Data Structures & AlgorithmsHardProduct company OA

A deque of indices gives the MINIMUM of every window of size 3 in [4, 2, 12, 3, 8, 1, 7]. What are the window minima?

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

Correct answer: A. 2, 2, 3, 1, 1

Windows: [4 2 12] → 2, [2 12 3] → 2, [12 3 8] → 3, [3 8 1] → 1, [8 1 7] → 1. The deque keeps increasing values; 3 evicts 12, and 1 evicts 8 and 3. '3, 3' for the fourth window ignores the newly arrived 1.

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

Exams that ask this topic