Skip to the code
+50 XP

#271 Total of Window Minimums

hard

A performance report takes every contiguous run of frame rates in fps (every subarray, of every length), finds its lowest value, and adds all those lowest values together as a "stutter score".

Write minimumTotal(fps) that returns that sum, modulo 1000000007 (10^9 + 7).

Example 1

Input: fps = [3,1,2,4]
Output: 17

The 10 subarrays have minimums 3, 1, 2, 4, 1, 1, 2, 1, 1, 1, which add up to 17.

Example 2

Input: fps = [11,81,94,43,3]
Output: 444

Summing the minimum of all 15 subarrays gives 444.

Constraints

  • 1 <= fps.length <= 2 * 10^5
  • 1 <= fps[i] <= 3 * 10^4
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).