Minimum length subarray with sum k

Asked atDelhivery
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 whether target is exact or at least k
  2. 02Ask whether negatives are permitted
  3. 03Use shrinking window for positive at-least version
  4. 04Use prefix sums for exact sum
  5. 05Use monotonic prefix deque for negative at-least version

Reference answer

Then expect these follow-ups

  • Why do negatives break the shrinking-window proof?

    Tests: correctness reasoning

  • Which prefix index should be stored for exact-sum minimum length?

    Tests: follow-up reasoning

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