Problem 305783 · easy · Phase 03 Linear Management & Searching

Worst Losing Streak

kadane · running minimum · subarrays

days lists a trader's daily result: positive numbers are gains, negative numbers are losses. Return the smallest possible total of a non-empty contiguous run of days, i.e. the worst streak.

Examples

Input:  days = [3, -4, 2, -5, 1]
Output: -7
Explanation: Days 2 to 4 total -4 + 2 - 5 = -7.
Input:  days = [1, 2, 3]
Output: 1
Explanation: Every run is positive; the single day worth 1 is the smallest.

Constraints

  • 1 <= len(days) <= 10**5, -10**4 <= days[i] <= 10**4.
  • Target complexity: O(n) time, O(1) extra space.

Goals

  • Adapt the running-best subarray idea to minimisation
  • Decide at every step whether to extend the current run or restart it
Starting Python…