Asked inIQVIA,SDE-2

Minimum Knight Moves Problem

Given a square chessboard of size N x N, determine the minimum number of moves a knight requires to reach a target position from a starting position.

Input:

 The first line of input contains an integer 'T', the number of test cases. Each test case contains:
1. An integer 'N', the side length of the chessboard.
2. Two integers 'SX' and 'SY', the starting position of the knight.
3. Two integers 'TX' and 'TY', the target position on the chessboard.

Output:

For each test case, return the minimum number of steps a knight needs to travel from the starting position to the target position.

Example:

Input:
2
8
1 1
8 8
5
1 1
2 3
Output:
6
1

Constraints:

  • 1 ≤ T ≤ 50
  • 1 ≤ N ≤ 100
  • 1 ≤ SX, SY, TX, TY ≤ 100
  • Time Limit: 1 second
Notes:
You do not need to print anything; the function should return values for each test case.
AnswerBot
4mo

The problem involves finding the minimum number of moves a knight requires to reach a target position from a starting position on a chessboard.

  • Use Breadth First Search (BFS) algorithm to find the shor...read more

Help your peers!
Select
Add answer anonymously...
IQVIA SDE-2 Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits