40. Snakes and Ladders | Code
Medium

Problem Statement

Return the least number of moves required to reach the square n^2 on a snakes and ladders board. If it is not possible, return -1.

Examples

1Example 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
2Example 2
Input:
{ "board": [ [ -1, -1 ], [ -1, 3 ] ] }
Output:
1
3Example 3
Input:
{ "board": [ [ -1, -1, -1 ], [ -1, 9, 8 ], [ -1, 8, 9 ] ] }
Output:
1
Loading...

Sign in to Run Code and Submit