Trains the technique from
LeetCode 2281Sum of Total Strength of WizardsThis 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 wind farm has its turbines standing in a single row. rating[i] is the output rating of the turbine at position i.
A stretch is any non-empty run of turbines at consecutive positions. The yield of a stretch is the smallest rating inside it multiplied by the total of all ratings inside it.
Audit every stretch of the row and return the sum of their yields. Stretches are identified by the positions they cover, so two stretches covering different positions are both counted even when their ratings happen to match.
The sum grows far past machine word size, so return it modulo 1000000007.
Example 1
The six stretches yield `7*7 = 49`, `3*3 = 9`, `8*8 = 64`, `3*10 = 30`, `3*11 = 33` and `3*18 = 54`, and those add up to 239, which is already below the modulus.
Example 2
The four single-turbine stretches yield 36, 36, 4 and 81. The adjacent pairs yield `6*12 = 72`, `2*8 = 16` and `2*11 = 22`, the triples yield `2*14 = 28` and `2*17 = 34`, and the whole row yields `2*23 = 46`. The total is 375.
Example 3
The two outer turbines each yield `1000000000 * 1000000000` on their own, the middle one yields 1, and the three stretches that include the middle turbine yield `1 * 1000000001`, `1 * 1000000001` and `1 * 2000000001`. The exact total is 2000000004000000004, and the answer is that value modulo 1000000007.
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_yield(rating: list[int]) -> int:public int totalStretchYield(int[] rating)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.