Reported September 2026
TikTokprefix sum

Maximum Rhombic Area Sum

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

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

The TikTok OA reported in September 2026 looks like a geometry puzzle, but it's really a sliding sum over a fixed diamond shape. You get a matrix and a radius r, and you need the best diamond sum where the whole diamond fits inside the grid. Matrix is up to 100 by 100, so a brute force pass over every center is fine if you're careful. The trap is the size of r and the edge handling. If you blank on the setup during the live assessment, StealthCoder runs invisibly as a safety net and gives you the working structure.

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

What it reduces to: loop over every valid center, where row and col are both at least r-1 and at most n-r and m-r. For each, sum the cells with |dr|+|dc| < r. Constraints cap r at about 50, so a diamond has up to roughly 2r^2 cells, around 5000. With 100 by 100 centers that's far fewer valid centers than 10,000 once r is large, so naive summing passes. The faster route is diagonal prefix sums, or adding a row-by-row strip: for each dr from -(r-1) to r-1, the width is r-1-|dr|, and a row prefix sum gives that strip in O(1). That's O(n*m*r). Pitfalls: off-by-one on the bounds, forgetting negatives so you can't init the max to 0, and r=1 where the answer is the max cell. If you freeze on the prefix setup in the live OA, StealthCoder is the hedge.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass TikTok's OA.

TikTok reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Maximum Rhombic Area Sum FAQ

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

Treat the diamond as stacked horizontal strips. For each row offset dr, the strip covers columns center-(r-1-|dr|) to center+(r-1-|dr|). Build row prefix sums and each strip is an O(1) lookup. Total work is O(n*m*r), which is comfortably fast here.

How do I find which centers are valid?+

The diamond extends r-1 cells up, down, left and right from the center. So the center row must be between r-1 and n-r, and the center column between r-1 and m-r. The constraint on r guarantees at least one valid center always exists.

Can I just brute force it?+

Often yes. The grid is at most 100 by 100 and r is capped near 50. Summing each diamond cell by cell is heavy when r is mid-sized, though. The row prefix sum version is only a few extra lines, so use it and stop worrying about time.

What edge cases should I test before submitting?+

Test r=1, where the answer is the largest single cell, including an all-negative matrix like Example 2. Test a 1 by 1 matrix. Test the max r where only one center is valid, like Example 1. Initialize your best to negative infinity, not zero.

How do I prepare for this in 48 hours?+

Write the brute force first and confirm it matches all three examples. Then convert the inner loop to row prefix sums. Practice the bounds math for centers until you can write it without thinking. That's one evening of work, and the pattern repeats in other grid-shape problems.

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

OA at TikTok?
Invisible during screen share
Get it