Loading...
Loading...
Loading...
Orders arrive in a row. Find the smallest number of consecutive orders whose total value is at least S. Print 0 if even all orders together are below S.
Example 1
Input
6 7 2 3 1 2 4 3
Output
2
4 + 3 = 7 is the shortest.
Example 2
Input
3 100 5 5 5
Output
0
Try the problem first. Open one hint at a time.
All values are positive, so a longer window never has a smaller total.
Grow the right end; while the total is big enough, record the length and shrink from the left.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor