Fewest Dice Rolls to Finish a Snakes and Ladders Board

Last updated: November 29, 2026

Quick Overview

Given an n by n Snakes and Ladders board numbered boustrophedon style from the bottom-left, where some squares send you to another square, return the minimum number of six-sided die rolls to reach the last square, or -1.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Given an n by n Snakes and Ladders board numbered boustrophedon style from the bottom-left, where some squares send you to another square, return the minimum number of six-sided die rolls to reach the last square, or -1.

An onsite question that layers a fiddly coordinate mapping on top of a BFS. Google interviewers use it to see whether you isolate the index conversion in a helper, test it, and then run a clean shortest-path search where each roll is one edge.

What the Interviewer Expects
  • Write a helper mapping square number to row and column
  • Handle the alternating direction of rows
  • Model each roll as an edge to up to 6 squares
  • Apply at most one snake or ladder per roll
  • Use BFS for the minimum number of rolls
Key Topics to Cover
BFS
coordinate mapping
shortest path
board game simulation
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if landing on a ladder top that is also a snake bottom chains moves?
  • Compute the expected number of rolls with random play.
  • What if the die has k faces?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • board[r][c] is -1 or the destination square of a snake or ladder.
  • Square 1 is bottom-left; rows alternate direction.
  • From square s, a roll moves to s+1..s+6 (capped at n*n), then follows at mo...
High-Level Design

Squares are nodes; each roll gives up to 6 edges, so BFS finds the minimum rolls. The only hard part is translating square number s to a grid cell. With q, rem = divmod(s - 1, n), the row from the...


Submit Your Answer
Markdown supported