Reported August 2026
Matroidsimulation

Diagonal Robot Path Sum

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

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

The data structure this Matroid problem hinges on is a plain visited set. That's it. The August 2026 report is a bouncing-robot simulation on a matrix, and the whole question is knowing when to stop. The robot moves diagonally, reflects off the walls, and quits at a corner or a repeat cell. If you've got an OA invite, expect to write a clean loop, not a clever algorithm. The traps are in the reflection order and the stop condition. StealthCoder sits invisibly on your screen as a safety net if you blank on the bounce logic mid-assessment.

The problem

You are given a rectangular integer matrix matrix and a starting cell with coordinates (cellX, cellY). Coordinates are zero-based: x is the row index and y is the column index.
A robot starts at (cellX, cellY), initially moving diagonally in direction (+1, +1). It adds the value of every newly visited cell to its sum, including the starting cell.
For each move, first consider the next cell (x + dx, y + dy). If that row would be outside the matrix, reverse dx. If that column would be outside the matrix, reverse dy. Then move one cell using the resulting direction.
The robot stops when it reaches a corner or a cell visited earlier. A corner reached for the first time is included in the sum. A previously visited endpoint is not counted again.
Return the sum collected by the robot. The starting cell is guaranteed not to be a corner.

Function
solution(matrix: int[][], cellX: int, cellY: int) → long

Examples
Example 1
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
cellX = 1
cellY = 1
return = 14
The robot starts at (1, 1), collecting 5. It next reaches corner (2, 2), collects 9, and stops. The total is 5 + 9 = 14.
Example 2
matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
cellX = 1
cellY = 1
return = 28
The visited cells are (1,1), (2,2), (1,3), and (0,2), contributing 6 + 11 + 8 + 3 = 28. The next move returns to (1,1), so the robot stops without adding that cell twice.

Constraints
matrix.length >= 2
matrix[row].length == matrix[0].length
matrix[0].length >= 2
(cellX, cellY) is a valid cell and is not a corner.

Reported by candidates. Source: FastPrep

Pattern and pitfall

This is simulation with a hash set. Store visited cells as (x, y) pairs, or as x * cols + y. Start at (cellX, cellY), add its value, then loop. Compute nx = x + dx and ny = y + dy. If nx is out of range, flip dx. If ny is out of range, flip dy. Then recompute the move with the new direction. After moving, check two things: is the new cell already in the set, and is it a corner? If it's visited, stop without adding. If it's a corner seen for the first time, add it and stop. The common pitfall is flipping only one axis, or adding a repeated cell's value twice. Use a 64-bit sum since the return type is long. The path is finite because states repeat, so the loop always ends. If you freeze on the reflection details, StealthCoder can give you a working loop live without the proctor seeing it.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Diagonal Robot Path 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 would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Matroid reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Diagonal Robot Path Sum FAQ

What's the trick in the Matroid diagonal robot problem?+

There's no deep trick. It's a simulation with a visited set. Reflect dx and dy independently when the next cell leaves the grid, move, then check for a corner or a repeat. Most failures come from the order of those checks.

How hard is this question really?+

Easy to medium. The logic is short, but the edge cases bite: reflecting both axes at once, counting a first-time corner, and not double-counting a revisited cell. Trace both examples by hand before you submit.

Do I need to track direction in the visited set?+

The problem says stop at a cell visited earlier, so tracking positions alone matches the spec. Example 2 confirms it, since returning to (1,1) ends the walk. Don't add direction to the key unless the statement says so.

What's the time complexity?+

Each cell is visited at most once before the robot stops, so time and space are O(rows * cols) in the worst case. In practice the diagonal path touches far fewer cells. Use a long or 64-bit integer for the sum.

How do I prepare for this in 48 hours?+

Write the simulation from scratch twice. Hand-trace a 3x3 and a 3x4 grid, including a start that hits a wall before a corner. Practice other bounce and reflection grid walks so the direction flip feels automatic.

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

OA at Matroid?
Invisible during screen share
Get it