Data Structures & AlgorithmsHardProduct Company SDE · CP practice
Problem: What is the number of paths from (1,1) to (3,3) moving only right or up in a grid with all cells free? Run the DP.
Problem: What is the number of paths from (1,1) to (3,3) moving only right or up in a grid with all cells free? Run the DP.
g = [[1] * 4 for _ in range(4)]
for i in range(2, 4):
for j in range(2, 4):
g[i][j] = g[i - 1][j] + g[i][j - 1]
print(g[3][3])What is printed?- A. 20
- B. 4
- C. 9
- D. 6
Correct answer: D. 6
From (1,1) to (3,3) needs 2 rights and 2 ups: C(4,2) = 6, which the DP builds from the boundary 1s. Starting from (0,0) gives C(6,3) = 20, 2² = 4 ignores ordering, and 9 counts cells.
More Coding Interview Problems questions
- Problem: How many distinct values does a XOR b take for a, b in {0, 1, 2, 3}? Run the code. python print(len({a ^ b for a in range(4) for…
- Problem: What is the sum of all integers in [1, 200] that are both odd and multiples of 5? Run the code. python print(sum(x for x in…
- Problem: What is the maximum number of distinct characters in a substring of length 4 of 'abcabcabc'? Run the code. python s = 'abcabcabc'…
- Problem: How many ways are there to tile a 2 x 6 board with 2 x 1 dominoes? Run the DP. python f = [1, 1] for n in range(2, 7)…
- 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…