Reported September 2026
Hudson River Tradingprefix sum

Maximum Rhombic Area Sum

Reported by candidates from Hudson River Trading's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Hudson River Trading OA. Under 2s to a working solution.
Founder's read

Hudson River Trading reported this one in September 2026, and the trap is hiding in the word "valid." Maximum Rhombic Area Sum looks like a simple grid scan until you realize a center only counts if the whole diamond fits inside the matrix. If you're taking this OA in the next couple of days, plan around that boundary rule first. The sums are the easy part. StealthCoder is there as a quiet safety net on the live assessment if your mind goes blank on the indexing, but you can walk in with the plan already in your head.

The problem

You are given a rectangular integer matrix matrix and a positive integer r.
A rhombic area of size r centered at (centerRow, centerCol) contains every cell (row, col) whose Manhattan distance from the center is less than r:
|row - centerRow| + |col - centerCol| < r
Equivalently, the center has radius number 1, its orthogonally adjacent cells have radius number 2, and all cells with radius numbers from 1 through r belong to the area.
A center is valid only when its entire rhombic area lies inside the matrix. Return the maximum sum of the matrix values in any valid rhombic area of size r.

Function
maximumRhombicSum(matrix: int[][], r: int) → int

Examples
Example 1
matrix = [[1,2,3],[4,5,6],[7,8,9]]
r = 2
return = 25
The only valid center is the middle cell. Its rhombic area contains 5, 2, 4, 6, and 8, whose sum is 25.
Example 2
matrix = [[-5,2],[3,1]]
r = 1
return = 3
With r = 1, each rhombic area contains only its center. The largest cell value is 3.
Example 3
matrix = [[1,1,1,1],[1,5,1,1],[1,1,4,1],[1,1,1,1]]
r = 2
return = 12
A rhombus centered at (1, 2) contains values 1, 1, 5, 1, and 4, for a sum of 12. The center (2, 1) also gives 12, and no valid center gives a larger sum.

Constraints
1 &le; matrix.length &le; 100
1 &le; matrix[i].length &le; 100
Every row has the same length.
-10^4 &le; matrix[i][j] &le; 10^4
1 &le; r &le; min((matrix.length + 1) / 2, (matrix[0].length + 1) / 2)

Reported by candidates. Source: FastPrep

Pattern and pitfall

The naive approach loops over every valid center and sums every cell in its diamond. With a 100 by 100 grid and r capped near 50, that's roughly 2500 centers times up to 5000 cells each. It can pass, but it's wasteful, and it's where people slip on bounds. The edge case: valid centers only run from row r-1 to rows-r, and the same for columns. Skip that check and you read out of bounds or count partial diamonds. Negative values matter too. Initialize the best to negative infinity, not zero, because every valid diamond could sum below zero. If you want it faster, use diagonal prefix sums or a row-wise sliding trick, where each row of the diamond is a contiguous span. That makes each center cost O(r). If you blank on the optimized version, StealthCoder can supply it live, but the brute force with correct bounds is a safe baseline.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Maximum Rhombic Area Sum cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Hudson River Trading's OA.

Hudson River Trading reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Rhombic Area Sum FAQ

What's the trick in Maximum Rhombic Area Sum?+

Restrict centers to rows r-1 through rows-r and columns r-1 through cols-r so the diamond always fits. Then sum each diamond row by row. Row offset d from the center covers a contiguous span of width 2*(r-1-|d|)+1, so row prefix sums make each row O(1).

How hard is this really?+

Medium. The idea is simple, but the boundary math and the negative values catch people. Brute force is easy to write. The row-prefix version takes a bit more care but isn't conceptually deep.

Is brute force fast enough here?+

Probably, given a 100 by 100 grid, but don't rely on it. Centers number up to about 2500 and each diamond can hold thousands of cells. Row prefix sums cut the per-center work to O(r), which is a much safer bet if the hidden tests are large.

What edge cases should I test before submitting?+

Test r = 1, where the answer is just the max cell, as in the second example. Test an all-negative matrix so your initial best isn't zero. Test a case where r is the maximum allowed, leaving exactly one valid center, like the first example.

How do I prepare for this in 48 hours?+

Write the brute force from scratch once, with the center bounds. Then add row prefix sums and check it against the three examples. Practice the span formula for each row offset. That's about an hour of work, and it covers the whole problem.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Hudson River Trading.

OA at Hudson River Trading?
Invisible during screen share
Get it