Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

For windows of size 3 over [3, 1, 4, 2, 5, 1, 6, 0], how many windows have their maximum at the last position of the window (ties count as yes)?

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

Correct answer: D. 3

Check each window's last element against the deque's front; ties count because the maximum equals the last element. Inspecting only strict maxima undercounts.

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

Exams that ask this topic