MEDIUMasked at 7 companies

Sum of Subarray Minimums

A medium-tier problem at 38% community acceptance, tagged with Array, Dynamic Programming, Stack. Reported in interviews at Paytm and 6 others.

Founder's read

Sum of Subarray Minimums is a medium-difficulty problem that appears in assessments for Google, Bloomberg, Flipkart, and smaller platforms like Paytm and PhonePe. The acceptance rate sits at 38%, which tells you most people either miss the pattern entirely or TLE on a brute force pass. The problem asks you to sum the minimum value across every possible subarray, modulo 10^9 + 7. The naive O(n^2) or O(n^3) approach looks tempting but fails on large inputs. The real solution uses a monotonic stack to precompute, for each element, how many subarrays it acts as the minimum within. If you hit this live and blank on the stack trick, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
7
Difficulty
MEDIUM
Acceptance
38%

Companies that ask "Sum of Subarray Minimums"

If this hits your live OA

Sum of Subarray Minimums is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.

Get StealthCoder
What this means

The trap is thinking you need to enumerate all subarrays and find their minimums, which leads to TLE. The insight is to flip the question: for each element in the array, count how many subarrays have that element as their minimum, then multiply the element by that count. A monotonic stack solves this by tracking the next and previous smaller elements for each index. You push elements in order, popping when you see a smaller one, which tells you the span of subarrays where the popped element is the minimum. This is a Dynamic Programming pattern at heart, but the stack is the mechanism that makes it O(n). Most candidates know stacks abstractly but freeze when they have to code the left/right boundary logic. When you're live and the brute force times out, StealthCoder gives you the pre-computed boundary arrays and the final loop, so you don't lose the whole problem to a 30-minute debugging spiral.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Sum of Subarray Minimums recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Sum of Subarray Minimums interview FAQ

Is this still asked at Google and Bloomberg?+

Yes. Both companies are in the top-asker list, and the problem is a classic medium-to-hard interview piece. It's a real filter. At Bloomberg especially, they often ask it in finance-adjacent contexts. If you see it in a real OA, you should assume it's a signals problem.

What's the trick I'm missing if I TLE?+

You're probably looping through all subarrays to find their min. Stop. Use a monotonic stack to precompute, for each element, the range of subarrays where it's the minimum. Multiply element by count, add to sum. That's O(n), not O(n^2).

How does this relate to 'next smaller element'?+

It's the same technique. A monotonic stack finds the next and previous smaller elements for each index. Here, you use that to bound the subarrays. If you've solved next smaller element, the stack pattern is identical. The difference is you also need to handle ties (equal elements) carefully to avoid double-counting.

Do I really need Dynamic Programming to solve this?+

Not explicitly. DP is the conceptual pattern (state: min so far, transition: extend or reset), but the stack is the implementation. You might see the DP angle in editorials, but the stack is the practical way to code it fast under interview pressure.

Why is acceptance only 38% if it's a classic problem?+

The monotonic stack pattern isn't obvious, and the modular arithmetic adds a third gotcha. Many candidates know the trick but implement it wrong (off-by-one on boundaries, forgetting modulo, not handling duplicates). It's a medium that punches like a hard.

Want the actual problem statement? View "Sum of Subarray Minimums" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.