Given an n x n board for the Snakes and Ladders game, return the minimum number of dice throws required to reach the final cell starting from cell 1. If the cell contains a snake or ladder, you must move to its destination. Pattern focus: BFS. Model each board cell as a node and each dice throw as one edge.
board = 2D game board
minimum dice throws to reach final cell
Example 1:
Input:
board = [[-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
Explanation:
A standard board where the minimum number of moves is 4.
Example 2:
Input:
board = [[-1,-1],[-1,3]]
Output:
1
Explanation:
A ladder can take you directly to the end in one move.
Example 3:
Input:
board = [[-1,-1],[-1,-1]]
Output:
1
Explanation:
On a 2x2 board, one throw can reach the final cell.