profits; bad days are negative. The owner wants the shortest stretch of consecutive days whose total profit is at least goal.
Return the length of that stretch (the number of days in it, at least one). If no unbroken stretch reaches goal, return -1.profits=[3, -4, 2, 5, -1, 4], goal=7 → 2
The consecutive days 2, 5 add up to exactly 7, which is 2 days. A single day is not enough: the best day brings 5.
profits=[4, -10, 4], goal=5 → -1
The two profitable days are split by a loss, and no unbroken stretch reaches 5. The answer is -1.
profits=[1, 1, 1, 1], goal=4 → 4
Only all four days together reach 4.
len(profits) ≤ 10⁵profits[i] ≤ 10⁵goal ≤ 10⁹profits=[3, -4, 2, 5, -1, 4], goal=7
2
Run checks the first 3 tests in your browser. Submit checks all 126 tests on the server, hidden ones included.