Sliding window Modifed version

Asked atInfosys
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. 01Ask for the exact modified constraint before committing to an algorithm.
  2. 02Define state that changes in O(1) when either pointer moves.
  3. 03Expand right and shrink left only while the defined invariant requires it.
  4. 04Prove each pointer is monotone and identify inputs that invalidate the approach.

Reference answer

Then expect these follow-ups

  • Give an example where a prefix-sum map is better.

    Tests: algorithm selection

  • How do you prove amortized O(n)?

    Tests: complexity

Hiring now

Get the Infosys interview, not just the prep

landed applies to roles like these for you, on each company’s own site, with answers written for the role.

Get 5x interviews10 free auto-applies. No card.
Or practice this question first

Next question