Search
⌘K

Leetcode 2281. Sum of Total Strength of Wizards

Compute the sum over all contiguous subarrays of (minimum element × sum of elements), which requires attributing each element’s contribution when it is the subarray minimum and aggregating many subarray sums efficiently. The typical solution uses a monotonic stack to find ranges where each element is the minimum combined with prefix-sum / prefix-of-prefix tricks to accumulate sums modulo 1e9+7.


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Your account is free and you can post anonymously if you choose.