![]() |
VOOZH | about |
Given a chessboard of size 8 x 8 and the current position of Mirandote. All the rules of this chess game are the same but the knight is modified. We call the new knight "Mirandote". The move of Mirandote is given by a 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.
Examples:
Input: row = 4, col = 4, steps = 1
Output: 12
All the 12 moves denoted by the following image by blue color :
Input: row = 4, col = 4, steps = 2
Output: 55
Solution:
We can observe that all the possible positions with respect to the current position can be written in the form of rows and columns. This is illustrated by the following image:
We can call a function recursively for each possible position and count all the possible positions.
Below is the required implementation to find the positions:
12
Time complexity of the above algorithm is O(12S), where S is the number of steps.
Space Complexity: O(n) where n is recursion stack space.