Ctrl K
Problem

Shortest Stretch to the Goal

Medium · Shortest Stretch to the Goal

A runner keeps a log: `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.…

Solve the problem →