Rotate image (square matrix) by 90 deg
Tue, 06 May 2025
Solution: If you do not want to read, you can watch the video below, else continue reading the post:
1. If the first tile is placed vertically.
The problem is now reduced to, "Find number of ways in which tiles can be placed on the board of length (n-1)".

The second tile has to be placed in the second row horizontally, there is no way to place it vertically.

The number of ways to arrange tiles in a board of length n = number of ways to arrange tiles in a board of length (n-1) +
number of ways to arrange tiles in a board of length (n-2)
This is the same recursive equation as that of Fibonacci series. The only difference is in the terminating conditions.
The two terminating conditions (for n=1, and n=2) are:
The fibonacci code will have a slight change in the terminating conditions as shown in the code below:
int numOfWays(int n)
{
if(n == 1)
return 1;
if(n == 2)
return 2; // THIS IS DIFFERENT FROM FIBONACCI
return numOfWays(n-1) + numOfWays(n-2);
}
Tue, 06 May 2025
Tue, 06 May 2025
Tue, 06 May 2025
Leave a comment