Bootcamps
Masterclasses
Menu
Courses
Account
Login / Sign Up

Tiling Problem

Medium Acceptance 50% Points 30

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.

Constraints
  • 1 = N = 30
Topics
Recursion
Companies
Microsoft
Added 19 Jul 2026 50% acceptance
Ln 1, Col 1Sign in to save your code
2
2