Minimum Knight Moves on a Finite Board
Updated
Problem statement
A knight starts at (startRow,startColumn) on a size by size board. Coordinates are zero-based. A move changes one coordinate by 2 and the other by 1, with either sign; every visited cell must stay on the board.
Return the minimum number of moves to reach (targetRow,targetColumn). Return -1 when unreachable, and 0 when start and target are the same.
Function
minimumKnightMoves(size: int, startRow: int, startColumn: int, targetRow: int, targetColumn: int) → intExamples
Example 1
size = 8startRow = 0startColumn = 0targetRow = 1targetColumn = 2return = 1One legal knight displacement reaches the target.
Example 2
size = 2startRow = 0startColumn = 0targetRow = 1targetColumn = 1return = -1No knight move fits on a 2x2 board, and the target differs from the start.
Constraints
1 <= size <= 100.0 <= startRow, startColumn, targetRow, targetColumn <= 99.- Every coordinate is smaller than size.
More Expedia Online Assessment questions
- Balanced NumbersOA · Seen Aug 2026
- REST API: Discounted PriceOA · Seen Aug 2026
- Maximum Team SizeOA · Seen Mar 2026
- Per-Domain Request LimiterOA · Seen Oct 2025
- Count Equal-Frequency SubsequencesOA · Seen Mar 2025
- Count Increasing Stock PeriodsOA · Seen Mar 2025
- Get Minimum StepsOA · Seen Oct 2024
- Rank Songs by PopularityOA · Seen Oct 2024
- Calculate the SumOA · Seen Oct 2024
- Get Maximum EfficiencyOA · Seen Oct 2024
Similar questions at other companies
- Shortest Path Around Rectangular ObstaclesDRW · OADRW interview questions
- House Bounds in a Ragged GridRippling · OA · PHONE SCREENRippling interview questions
- Grid Path With the Most ClearanceDocuSign · OADocuSign interview questions
- Maximum Damage PatchGecko Robotics · OA · PHONE SCREEN
- Directed Path ExistenceUnity · OA
- Rotting OrangesSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Minimum Time to Spread Through a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
- Minimum Time to Rot All OrangesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions