Path Through an O/X Grid Using Only Right and Down
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon reportedly served this one in September 2026, and the grid can hit 250000 cells, so sloppy recursion over every path will die. It looks like a BFS problem. The hinted pattern is breadth-first search, but the right-and-down-only rule means you don't need a queue at all. If you've got an OA invite and 48 hours, this is a good one to nail cold. StealthCoder sits invisibly on your screen as a safety net if you blank during the live assessment, but the idea here is short enough to own yourself.
The problem
Given a rectangular array of strings grid, a zero-based coordinate source = [row, col], and a zero-based coordinate destination = [row, col], return whether the destination is reachable. The character O is open and X is blocked. From an open cell you may move exactly one cell right or one cell down. A blocked endpoint is unreachable, and a destination above or left of the source is also unreachable. Function hasRightDownPath(grid: String[], source: int[], destination: int[]) → boolean Examples Example 1 grid = ["OOO","OXO","OOO"] source = [0,0] destination = [2,2] return = true Move right twice and then down twice while avoiding the center obstacle. Example 2 grid = ["OX","XO"] source = [0,0] destination = [1,1] return = false Both first moves enter blocked cells. Example 3 grid = ["OOO"] source = [0,2] destination = [0,0] return = false Reaching the destination would require moving left. Constraints 1 <= grid.length, grid[i].length <= 500. Every row has the same length, and the grid has at most 250000 cells. Every cell is O or X. source and destination each contain exactly two valid grid coordinates.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Brute force tries every path of rights and downs. That's exponential, and with a 500 by 500 grid it never finishes. The trick is that moves only go right or down, so there are no cycles and each cell has one answer: reachable from source or not. Run a DP over the sub-rectangle from source to destination. A cell is reachable if it's open and either the cell above or the cell to its left is reachable. Seed the source as true. Pitfalls: check that the source and destination are both O, check that the destination row and column are not less than the source's, and don't iterate outside the rectangle. BFS or DFS with a visited set also works in O(rows*cols), but the DP is cleaner and uses less memory. If you freeze mid-assessment, StealthCoder is the hedge that gives you the DP while you keep typing.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Path Through an O/X Grid Using Only Right and Down 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Path Through an O/X Grid Using Only Right and Down FAQ
What's the trick in this Amazon grid path problem?+
Moves are only right or down, so there are no cycles. A cell is reachable if it's open and the cell above or to its left is reachable. Fill that table from the source to the destination in one pass. No recursion over paths, no visited set needed.
Do I need BFS since it's hinted as breadth-first search?+
No. BFS with a visited set works and runs in O(rows*cols), but the direction restriction makes a simple DP simpler and safer. Either passes the 250000 cell limit. Pick the one you can write without bugs under pressure.
What edge cases break most solutions?+
A blocked source or destination, a destination above or left of the source, and source equal to destination on an open cell. Example 3 tests the left-move case. Check these first and return false early before any loop runs.
Why does brute force fail here?+
Counting every right and down path grows exponentially with grid size. With up to 500 rows and 500 columns, you'd never finish. The grid has at most 250000 cells, so you need a solution that touches each cell once, which is O(rows*cols).
How do I prepare for this in 48 hours?+
Write the reachability DP from scratch twice, once on a full grid and once restricted to the source-to-destination rectangle. Then test the three examples plus a blocked endpoint. Practice grid reading speed and indexing, since off-by-one errors are the real risk.