Reported October 2026
Amazonbreadth first search

Minimum Moves to Capture the King

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

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

A piece sits at [0,0] on an 8x8 board, the king is at [7,7], and the answer is seven diagonal moves. That's the example in the Amazon OA reported in October 2026, and it hides the real task: find the fewest moves given a custom list of directions. It's a shortest path on a grid, so think breadth-first search. The example looks trivial, but the hidden tests won't be. If you blank on the queue setup mid-assessment, StealthCoder runs invisibly as a safety net and hands you the solution while you keep your head.

The problem

A piece starts at start on an empty rows-by-cols board and must capture the king at king.

Examples
Example 1
rows = 8
cols = 8
start = [0,0]
king = [7,7]
directions = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
return = 7
Seven diagonal moves reach the opposite corner.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Treat each cell as a node and each direction as an edge. Every move costs one, so BFS from start gives the minimum moves the first time you pop the king's cell. Keep a visited set or a rows-by-cols boolean grid, and push (row, col, dist) into a queue. Bounds-check every neighbor against rows and cols. The common pitfalls: marking visited on pop instead of on push, which blows up the queue, and forgetting the case where start equals king, which should return 0. Also handle unreachable cases, likely -1, if the directions can't reach the target. Check the statement for that. Don't use DP or greedy here. Greedy diagonal stepping only works for the example. If the live OA freezes you, StealthCoder can supply the BFS template as a hedge, but the logic is short enough to write cold.

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 Minimum Moves to Capture the King 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

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as minimum knight moves. If you have time before the OA, drill that.

⏵ The honest play

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

Amazon 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.

Minimum Moves to Capture the King FAQ

What's the trick in Minimum Moves to Capture the King?+

Model the board as a graph and run BFS from start. Each direction in the list is an edge with cost one. The first time you reach the king's cell, that distance is the minimum. Don't try a formula, because the directions can be custom.

How hard is this Amazon OA question really?+

Easy to medium. It's a standard grid BFS with a configurable direction list. If you've written BFS on a matrix before, it takes about fifteen minutes. The risk is edge cases, not the algorithm.

Which edge cases should I test?+

Start equals king, so return 0. A king that's unreachable with the given directions. A 1x1 board. A board with only one row or column. Also confirm whether the pieces can slide multiple squares or only step once, by reading the statement carefully.

Should I use BFS or DFS?+

BFS. Every move costs the same, so BFS guarantees the shortest path the first time it reaches the target. DFS would need to explore all paths and track the minimum, which is slower and easy to get wrong on larger boards.

How do I prepare for this in 48 hours?+

Write grid BFS from memory two or three times. Use a deque, a visited grid, and a directions array. Practice marking visited when you push. Then test with a custom directions list like knight moves, since that's the likely twist in the hidden cases.

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

OA at Amazon?
Invisible during screen share
Get it