Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: Snakes and ladders on squares 1–30: from square s, a die roll of r moves you to s + r (for 1 ≤ r ≤ 6, if s + r ≤ 30). Ladders: 3→22, 5→8, 11→26; snakes: 27→1, 21→9. Landing on a ladder's foot moves you to its top at once. What is the minimum number of die rolls to go from square 1 to square 30?
- A. 4
- B. 2
- C. 3
- D. 5
Correct answer: C. 3
BFS over squares, with each roll followed by any ladder or snake at the landing square. Ignoring the instant transport on the ladders gives a longer count.
More Coding Interview Problems questions
- Problem: Nim with three piles of sizes 1, 2 and 3. A move removes any positive number of stones from one pile. The player who takes the…
- Problem: How many subarrays of [1, 2, 3, 0, 3, 2, 1] have a XOR of zero?
- Problem: How many integers from 1 to 50 have exactly two 1-bits in their binary representation?
- Problem: What is the sum of the decimal digits of 9⁹?
- Problem: Arrange the numbers 3, 30, 34, 5, 9 so that their decimal concatenation is the largest possible number. What is that largest…
- Problem: Minimum number of jumps to reach the last index of [2, 3, 1, 1, 4] when from index i you may jump up to a[i] steps forward. What…