ShareChat Coding Question – Solved

9 Live
1. Question 1 Given a chessboard of n rows (top to bottom) and n columns (left to right). In each move, a knight moves either: 2 column positions and 1 row position 2 row positions and 1 column position In other words, a move is 2 steps along one axis and 1 step along a perpendicular axis. Given a starting position A and ending position B, calculate the minimum number of moves needed by the knight to move from A to B if it is possible. If it is not possible, return -1. All moves must remain within the chessboard. Example n = 9 startRow = 4 startCol = 4 endRow = 4 endCol = 8 The chessboard has a size of 9 x 9. Starts at the position (startRow, startCol) = (4, 4). - Move 1 step up or down, then 2 steps right to reach either the position (3,6) or (5,6). - Move 2 steps right and 1 step down or up as...

Asked in: ShareChat

Image of the Question

Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| A traveler is traveling from the city of Zeta to Omega. He starts with X amount… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |