Notice Period

Best Streak

medium

A food truck logs its daily profit (or loss) as a list of integers — one entry per day, negatives included.

The owner wants to brag about her single best consecutive run of days: the contiguous stretch whose profits sum to the largest total.

Given profits, return that maximum sum. The stretch must contain at least one day.

Example 1
in profits = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
out 6
The run [4, -1, 2, 1] sums to 6 — no other contiguous stretch beats it.
Example 2
in profits = [-3, -1, -7]
out -1
Every day loses money; the least-bad single day is -1.
Constraints
  • · 1 <= len(profits) <= 10^4
  • · -10^4 <= profits[i] <= 10^4
similar problem on LeetCode ↗
solution.pyloading python…
test results
Hit ▶ Run to test your code against the visible cases.