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?

  1. A. 4
  2. B. 2
  3. C. 3
  4. 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

Exams that ask this topic