FastPrepMinimum Moves to Capture the King
Problems/Minimum Moves to Capture the King

Minimum Moves to Capture the King

Amazon logoAmazon● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon full-time phone screen. The report asks for the fewest moves for a piece to capture a king, first with all eight neighboring directions, and then with direction sets that depend on the piece. We added the board limits so the answer is always the same. Our version is about 76% the same as the reported question.

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

For each move, choose exactly one row-and-column offset from directions and add it to the piece’s current position. It may not leave the board. Return the minimum number of moves needed to reach the king, or -1 if the king is unreachable.

Function

minimumMovesToCaptureKing(rows: int, cols: int, start: int[], king: int[], directions: int[][]) → int

Examples

Example 1

rows = 8cols = 8start = [0,0]king = [7,7]directions = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]return = 7

Diagonal moves are allowed, so the piece can step down and to the right each time. Seven such moves take it from the top-left corner to the king in the opposite corner.

Example 2

rows = 8cols = 8start = [0,0]king = [7,7]directions = [[-1,0],[0,-1],[0,1],[1,0]]return = 14

Only one-cell moves up, down, left or right are allowed, so no move is diagonal. The piece must walk down the whole board and across the whole board one step at a time, which takes fourteen moves.

Constraints

  • 1 <= rows, cols <= 200.
  • Start and king are valid board cells.
  • 1 <= directions.length <= 8.
  • Each direction is a row change and a column change. Both are whole numbers from -1 to 1, and they are not both zero. No two directions are the same.

More Amazon Phone Screen questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
  • Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
  • Word Chain Jumps in a GridGoogle · PHONE SCREENGoogle interview questions
  • Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
  • Count Connected IslandsUber · PHONE SCREENUber interview questions
  • Number of IslandsSpaceX · PHONE SCREENSpaceX interview questions
  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
  • Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
  • Xiangqi Horse ReachabilityeBay · PHONE SCREENeBay interview questions
  • Grid Pathfinding with Obstacles (DFS)Roblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions

Interview reports that mention this question

  • Amazon SDE II (L5) Interview Questions: 5 Experiences

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int minimumMovesToCaptureKing(int rows, int cols, int[] start, int[] king, int[][] directions) {
        // Write your code here.
    }
}
Checking account…