ShareChat Coding Question – Solved

2 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

| The supply chain manager at one of Amazon's warehouses is shipping the last con… |
| Determine the highest value after executing n steps on an infinite 2D grid that… |
| Amazon Prime Video is developing a new feature called "Segmentify." This featur… |
| In this new stock prediction game launched on Amazon Games, Player 1 provides P… |
| Amazon operates numerous warehouses, with each warehouse holding inventory[i] u… |
| In Amazon's highly efficient logistics network, minimizing operational overhead… |