Tiling Problem
You have been given a board where there are '2' rows and 'N' columns. You have an infinite supply of 2x1 tiles, and you can place a tile in the following ways:
1. Horizontally as 1x2 tile
2. Vertically as 2x1 tile
Count the number of ways to tile the given board using the available tiles.
Note :
The number of ways might be large so output your answer modulo 10^9 + 7.
Here an example of tile and board for 'N' = 4 :
Input format :
The first and only line of each test case contains an Integer 'N' which denotes the size of the board, i.e. '2' rows and 'N' columns.
Output format :
For each test case, print the number of ways to tile the board modulo 10^9 + 7.
Note:
You are not required to print the output explicitly, it has already been taken care of. Just implement the function.
Constraints :
1 <= N <= 10^18
Where 'N' is the number of columns in the board.
Time limit: 1 sec
CodingNinjas
author
3y
Recursion And Memoization (Runtime error)
Try to place the tile to fill the unit column and calculate the number of ways from smaller sub-problems. Then use memoization to convert O(2^N) solution to an...read more
CodingNinjas
author
3y
Iterative DP
Try to place the tile to fill the unit column and calculate the number of ways from smaller sub-problems. We can use bottom-up DP with keeping the previous two values.
- At any point we are a...read more
CodingNinjas
author
3y
Matrix Exponentiation
We can observe that the solution of this problem for 2xN Board is (N-1)th Fibonacci Number.
We can calculate the ‘N’th Fibonacci Number using Binary Matrix Exponentiation explained...read more
Add answer anonymously...
Top Adobe Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app