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!
Add answer anonymously...
Interview Questions Asked to SDE-2 at Other Companies
Top Skill-Based Questions for IQVIA SDE-2
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

