Data Structures & AlgorithmsModerateProduct Company SDE · CP practice
Problem: How many ways are there to tile a 2 x 6 board with 2 x 1 dominoes? Run the DP.
Problem: How many ways are there to tile a 2 x 6 board with 2 x 1 dominoes? Run the DP.
f = [1, 1]
for n in range(2, 7):
f.append(f[-1] + f[-2])
print(f[6])What is printed?- A. 8
- B. 21
- C. 64
- D. 13
Correct answer: D. 13
f(n) = f(n−1) + f(n−2) with f(0) = f(1) = 1 gives 1, 1, 2, 3, 5, 8, 13, so 2 × 6 has 13 tilings. One step short gives 8, one too far gives 21, and 2⁶ = 64 treats each column independently.
More Coding Interview Problems questions
- Problem: What is the minimum number of edges to remove from a 5-vertex complete graph to leave a spanning tree? Run the code (answer = E…
- Problem: How many integers from 1 to 10^6 have exactly one set bit (power of two)? Run the code. python print(sum(1 for x in range(1, 10 6…
- Problem: What is the maximum number of points on a line among (0,0), (1,1), (2,2), (3,5), (4,4) (collinear with the diagonal)? Run the…
- Problem: What is the time complexity of the Hopcroft-Karp algorithm for maximum matching on V vertices and E edges?
- Problem: Which technique gives the answer to 'minimum number of platforms' by sorting events?
- Problem: Which of these is the standard O(n log n) algorithm for the longest increasing subsequence?