Data Structures & AlgorithmsVery hardGATE CS
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 paths exist?
- A. 222
- B. 152
- C. 285
- D. 321
Correct answer: B. 152
Count with the recurrence f(x,y)=f(x+1,y)+f(x,y+1)+f(x+1,y+1) and f(2,2)=0, giving 152. Without the restriction there are 321 paths (Delannoy number D(4,4)); paths through (2,2) number D(2,2)² = 13² = 169, and subtracting only 6² = 36 (the diagonal-free count) leaves the wrong 285.
More Coding Interview Problems questions
- 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".
- What is the minimum number of characters that must be inserted anywhere in "CBAABDCABBDAC" to make it a palindrome?
- Matrices A1…A7 have dimensions 5×10, 10×3, 3×12, 12×5, 5×50, 50×6, 6×8. What is the minimum number of scalar multiplications needed to…
- A 2 × 11 board is tiled completely using 1 × 2 dominoes (placed either way) and 2 × 2 squares. How many different tilings are there?