Snakes and Ladders
Return the minimum number of moves to reach the last square or -1 if impossible.
Examples
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]]
Output: 4
Input: [[-1,-1],[-1,3]]
Output: 1
Hints
Consider how to handle squares with snakes or ladders (teleportation) when building the graph.
Think about how to represent the board as a graph where edges account for both normal moves and teleportation.
Explore how to use BFS to track the minimum moves while avoiding revisiting squares unnecessarily.
Related Problems
Snakes and Ladders
Return the minimum number of moves to reach the last square or -1 if impossible.