Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5765 |

@blackshadows | 5715 |

@akhayrutdinov | 5111 |

@mb1973 | 4993 |

@Quandray | 4944 |

@saiujwal13083 | 4506 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3516 |

@sushant_a | 3459 |

@verma_ji | 3341 |

@KshamaGupta | 3318 |

Complete Leaderboard | |

Handle | Score |

@aroranayan999 | 1272 |

@bt8816103042 | 739 |

@rohitanand | 495 |

@codeantik | 479 |

@shalinibhataniya1097 | 472 |

@amrutakashikar2 | 464 |

@thealchemist627 | 456 |

@dalwainazism125 | 453 |

@shivanandp12345678910 | 453 |

@akashkale117 | 453 |

@SherlockHolmes3 | 447 |

Complete Leaderboard |

Given a floor of dimensions 2 x W and tiles of dimensions 2 x 1, the task is to find the number of ways the floor can be tiled. A tile can either be placed horizontally i.e as a 1 x 2 tile or vertically i.e as 2 x 1 tile. Print the answer modulo 10^{9}+7.

**Example 1:**

Input:W =3Output:3Explanation:We need 3 tiles to tile the board of size 2 x 3. We can tile in following ways: 1) Place all 3 tiles vertically. 2) Place first tile vertically. and remaining 2 tiles horizontally. 3) Place first 2 tiles horizontally and remaining tiles vertically.

**Example 2:**

Input:W =4Output:5Explanation:For a 2 x 4 board, there are 5 ways 1) All 4 vertical 2) All 4 horizontal 3) First 2 vertical, remaining 2 horizontal. 4) First 2 horizontal, remaining 2 vertical. 5) Corner 2 vertical, middle 2 horizontal.

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **numberOfWays()** which takes an Integer N as input and returns the answer.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 <= N <= 10^{5}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Ways To Tile A Floor

...