dsa · medium
Snakes and Ladders (min throws)
GreyOrangeGraphQueue
board is n×n. Cells labeled 1..n² in boustrophedon from bottom-left. -1 means no teleport; a positive number is the destination of a snake/ladder. Start at 1, need n². Each throw is 1..6. Return min throws, or -1.
Arguments
board— the 2D board
Related to the Principal 2025 LLD (board *generator*); this is the BFS play on a board.
**Example:** the 6×6 board in the samples takes 4 throws.
Constraints
2 <= n <= 20 (n=1 allowed in tests) Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,35,-1,-1,13,-1],[-1,-1,-1,-1,-1,-1],[-1,15,-1,-1,-1,-1]] Expected: 4