steps[i] is how many kilometres they ran on day i, and every value is positive. The coach wants the shortest run of consecutive days that adds up to at least goal kilometres.
Return the length of that run in days. If even all the days together fall short of goal, return 0.
Once you have an O(n) solution, try finding an O(n log n) one as well.goal=10, steps=[3, 1, 6, 2, 5, 4] → 3
The consecutive days [6, 2, 5] give 13 ≥ 10, which is 3 days. No two neighbouring days are enough: the best pair is 5 + 4 = 9.
goal=8, steps=[2, 9, 1] → 1
The single day with 9 is already enough.
goal=20, steps=[4, 4, 4] → 0
Even all days together give only 12, so the answer is 0.
goal ≤ 10^9steps.length ≤ 10^5steps[i] ≤ 10^4goal=10, steps=[3, 1, 6, 2, 5, 4]
3
Run checks the first 3 tests in your browser. Submit checks all 75 tests on the server, hidden ones included.