Sum of Maximums of Every Window of Size K

Asked atWalmart
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below
0
Stuck? Show a way to structure it+
  1. 01Validate k is between one and array length.
  2. 02Keep indices in a deque with values decreasing from front to back.
  3. 03Remove expired front indices and dominated back indices for each new element.
  4. 04After a full window, add the front value to the running answer.

Reference answer

Then expect these follow-ups

  • Why is the deque monotonic?

    Tests: invariant

  • How do duplicates affect the back-pop comparison?

    Tests: edge cases

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question