Given a chessboard of size 8 x 8 and the current position of Mirandote. All the rules of this chess game are same but the knight is modified, we call new knight as “Mirandote”. The moves of Mirandote is given by blue color where its current position is denoted by red color in the following image :
The task is to find how many possible positions exist in Chessboard that can be reached by Mirandote in exactly S steps.
Input: row = 4, col = 4, steps = 1
All the 12 moves denoted by the following image by blue color :
Input: row = 4, col = 4, steps = 2
We can observe that all the possible position with respect to current position can be written in the form of row and column. This thing is illustrated by the following image :
We can call a function recursively for each possible position and count all the possible position.
Below is the required implementation to find the positions:
Time complexity of the above algorithm is O(12S), where S is the number of steps.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.