Trains the technique from
LeetCode 907Sum of Subarray MinimumsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A pipeline carries gauges at consecutive pumping stations. readings[i] is the pressure the gauge at station i reports.
A stretch is any block of one or more neighbouring stations. What a stretch can push through is set by its weakest gauge, so a stretch is rated at the smallest reading inside it. A pipeline of n stations therefore has n * (n + 1) / 2 stretches, each with its own rating.
Add together the ratings of all the stretches. The figure climbs fast, so give it as a remainder modulo 10^9 + 7.
Example 1
The four single stations are rated 4, 2, 3 and 6, the three pairs are rated 2, 2 and 3, the two triples are rated 2 and 2, and the whole line is rated 2, which adds to 28.
Example 2
Each station on its own is rated 2, and the stretch holding both of them is rated 2 as well, giving 6.
Example 3
A single station forms one stretch, and its rating is its own reading.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def total_stretch_minimums(readings: list[int]) -> int:public int totalStretchMinimums(int[] readings)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.