MEDIUMasked at 2 companies

Maximum Sum of an Hourglass

A medium-tier problem at 76% community acceptance, tagged with Array, Matrix, Prefix Sum. Reported in interviews at Nutanix and 1 others.

Founder's read

You're staring at a grid and need to find the maximum sum of hourglass shapes. Nutanix and Zoho both ask this, and at 76% acceptance, it looks easy until you realize the naive approach hammers your runtime. The trick is recognizing that an hourglass is just a fixed pattern of nine cells, and you can't optimize it with classic prefix sums the way you'd think. If this hits your live OA and the obvious solution doesn't feel right, StealthCoder solves it in seconds, invisible to the proctor.

Companies asking
2
Difficulty
MEDIUM
Acceptance
76%

Companies that ask "Maximum Sum of an Hourglass"

If this hits your live OA

Maximum Sum of an Hourglass 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 a senior engineer who knows the OA is theater. This is the script.

Get StealthCoder
What this means

An hourglass is a 3x3 subgrid with the middle row's edges included: top row (3 cells), middle cell (1 cell), bottom row (3 cells). The brute force approach is correct here: iterate through every valid top-left corner and sum the nine cells. Most candidates overthink the Prefix Sum topic tag and try to precompute, but that's overkill for small grids. The real pitfall is off-by-one errors on boundary checks or mixing up row and column indices. Once you lock in the loop bounds and the fixed sum pattern, it's linear in grid size. StealthCoder is your hedge if the indexing logic trips you up under time pressure during the assessment.

Pattern tags

The honest play

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

Maximum Sum of an Hourglass 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 a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Sum of an Hourglass interview FAQ

Is this really just a nested loop problem?+

Yes. Iterate through valid hourglass positions, sum the nine cells at each, track the max. Boundary check ensures your top-left corner doesn't go too far right or down. No fancy structure needed. The Prefix Sum tag is a red herring for this one.

Why does Nutanix and Zoho ask this if it's straightforward?+

It's a filter for sloppy code. Boundary arithmetic and index handling trip up careless candidates fast. Clean implementation in 5 minutes separates people who can think clearly under pressure from those who panic and hardcode.

How does Prefix Sum relate to this problem?+

It doesn't, really. A 2D prefix sum works for rectangular regions, not the hourglass shape. The tag likely appears because the problem lives in a matrix topic cluster. Stick with direct enumeration and you'll be fine.

What's the most common mistake candidates make?+

Off-by-one errors on loop bounds. If your grid is m x n, the top-left corner of an hourglass can only go to row m-3 and column n-3. Get this wrong and you either crash or silently skip valid hourglasses.

Can I optimize this below O(m*n)?+

No. You must check every hourglass. Grids in this problem are typically small, so brute force is the intended solution. Write clean code and move on.

Want the actual problem statement? View "Maximum Sum of an Hourglass" 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.