Quant Memo
Coding/●●●●●

Shortest window that reaches a target sum

Given an array nums of positive numbers and a target, find the length of the shortest contiguous run whose sum is at least target. Return 0 if no run qualifies.

target = 7, nums = [2, 3, 1, 2, 4, 3]
-> 2          # [4, 3] sums to 7

Aim for O(n)O(n). The window size is not fixed here, so you cannot just slide a rigid frame.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions