FastPrepKnight Minimum Moves
Problems/Knight Minimum Moves

Knight Minimum Moves

IMC Trading logoIMC Trading● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading new grad online assessment. Our version is about 99% the same as the original screenshot. The fixed-bishop variant that was reported separately is a different exercise.

A knight starts at (startRow,startCol) on a square board with n rows and n columns. Coordinates are zero-based.

Each move changes one coordinate by 2 and the other by 1, independently choosing either sign. Every landing square must remain inside the board.

Return the minimum number of moves to (endRow,endCol), or -1 if the target cannot be reached. The board has no obstacles or other pieces.

Function

minMoves(n: int, startRow: int, startCol: int, endRow: int, endCol: int) → int

Examples

Example 1

n = 9startRow = 4startCol = 4endRow = 4endCol = 8return = 2
Example 1 illustration

Use legal two-by-one knight jumps that stay inside the square board. No obstacle or bishop is present.

Example 2

n = 4startRow = 0startCol = 0endRow = 1endCol = 2return = 1

Use legal two-by-one knight jumps that stay inside the square board. No obstacle or bishop is present.

Example 3

n = 4startRow = 1startCol = 1endRow = 1endCol = 1return = 0

Use legal two-by-one knight jumps that stay inside the square board. No obstacle or bishop is present.

Constraints

  • 4 <= n <= 150
  • All start and end coordinates satisfy 0 <= coordinate < n.

More IMC Trading Online Assessment questions

  • Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
  • Grid Paths with Override PassesOA · Seen Oct 2026
  • Weighted LFU CacheOA · Seen Sep 2026
  • Rock JumpingOA · Seen Aug 2026
  • Stack Batch RemovalOA · Seen Aug 2026
  • Chain of CommandOA · Seen Aug 2026
  • Choose ContainersOA · Seen Aug 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Can Every Package Fit in a BoxOA · Seen Jul 2026

Similar questions at other companies

  • Base Unit ConversionsAdobe · OAAdobe interview questions
  • Delivery Management SystemAkuna Capital · OAAkuna Capital interview questions
  • Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
  • Tree Pythagorean TriplesIBM · OAIBM interview questions
  • Shortest Atom Action PathOpenAI · OAOpenAI interview questions
  • Distances to CyclesBelvedere Trading · OA
  • Shortest Path from an Encoded GraphIntuit · OAIntuit interview questions
  • Minimize Malware Spread by Removing a NodeVisa · OAVisa interview questions
  • Longest Distance in a Frequency-Limited NetworkBloomberg LP · OABloomberg LP interview questions
  • Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions

Interview reports that mention this question

  • IMC Trading OA: What It Tests (2026)

IMC Trading interview experiences

  • IMC Trading SWE OA and Video: 18 Experiences (Part 3 of 3)
  • IMC Trading SWE OA Questions: 22 Experiences (Part 2 of 3)
  • IMC SWE New Grad OA and Interviews: 58 Experiences (Part 1 of 3)
All IMC Trading interview questionsSee IMC Trading hiring insights
Saved
class Solution {
    public int minMoves(int n, int startRow, int startCol, int endRow, int endCol) {
        // Write your solution here.
    }
}
Checking account…