Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Tiling Problem

Medium Acceptance 50.00% Points 30.00

You are given a board of size 2 × N and an unlimited number of 2 × 1 tiles. Each tile can be placed either vertically or horizontally. Calculate and return the total number of ways to completely tile the board.

Examples
Example 1

Example 1

Input: N = 5

Output: 8

Explanation: For a 2 × 5 board, you can either place one vertical tile and solve for length 4, or place two horizontal tiles and solve for length 3. Combining these possibilities gives 8 total ways.

Example 2

Example 2

Input: N = 6

Output: 13

Explanation: The number of ways equals the sum of ways for lengths 5 and 4 (8 + 5), resulting in 13 possible tilings.

Example 3

Example 3

Input: N = 7

Output: 21

Explanation: Similarly, ways for length 7 = ways(6) + ways(5) = 13 + 8 = 21 total arrangements.

Hints
Hint 1
N/A
Constraints
  • 1 = N = 30
Companies
Microsoft
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions