Data Structures & AlgorithmsHardTCS NQT · Infosys
A robot moves only right or down from the top-left to the bottom-right cell of this 6×6 grid, where # is a blocked cell and . is free: ...... ..#... .#..#. ....#. #..... ...... How many distinct paths exist?
- A. 20
- B. 24
- C. 18
- D. 15
Correct answer: C. 18
Run dp[i][j] = dp[i-1][j] + dp[i][j-1] with dp = 0 on blocked cells and dp[0][0] = 1. The bottom-right entry evaluates to 18.
More Coding Interview Problems questions
- For the array [4, 5, 0, -2, -3, 1, 7, -9, 6] and k = 5, how many non-empty contiguous subarrays have a sum divisible by k?
- How many pairs of indices (i, j) with i < j satisfy a[i] > 2·a[j] in a = [5, 2, 6, 1, 7, 3, 9, 2, 4]?
- A walker moves from (0,0) to (4,4) on lattice points using steps (1,0), (0,1) and (1,1). The point (2,2) is forbidden. How many different…
- How many permutations of {1, 2, …, 8} have exactly two fixed points (positions i with π(i) = i)?
- How many integers n with 1 ≤ n ≤ 999 have digit sum exactly 12 and contain no digit 0 (in their usual decimal form, without leading zeros)?
- Find the length of the longest common subsequence of X = "AGGTABQXZRYWM" and Y = "GXTXAYBZQMWRY".