Data Structures & AlgorithmsHardProduct Company SDE · lattice paths
Problem: How many monotone (right and up) lattice paths from (0,0) to (5,7) pass through the point (2,3)? Run the code.
Problem: How many monotone (right and up) lattice paths from (0,0) to (5,7) pass through the point (2,3)? Run the code.
from math import comb print(comb(5, 2) * comb(7, 3))What is printed?
- A. 210
- B. 420
- C. 126
- D. 350
Correct answer: D. 350
C(5,2) = 10 paths reach (2,3) and C(7,3) = 35 paths continue to (5,7), giving 10 * 35 = 350.
More Coding Interview Problems questions
- Problem: A grid has 4 rows and 4 columns. Cell (r, c) holds value (r·c) mod 3. Starting at (0,0), a path moves right or down to (3,3)…
- Problem: The string "mississippi" has its letters counted. What is the number of distinct letters that appear an odd number of times?
- Problem: Start with 7, multiply it by 3, then repeatedly replace the number by the sum of its decimal digits until a single digit remains…
- Problem: The array [4, 1, 3, 2, 5] is processed by counting sort on the values 1 to 5, writing the values into an output array in sorted…
- Problem: For the set {2, 3, 4, 6, 8, 9, 12}, how many pairs (x, y) with x < y have x dividing y?
- Problem: A bag contains 2 red, 3 green and 4 blue balls. How many ways are there to choose 3 balls so that all three have different colours?