Naukri Interview Snake and Ladder BFS
Naukri Interview Snake and Ladder BFS
HardQueues100% accepted
A board game has n*n cells numbered 1 to n*n in Boustrophedon order. Snakes/ladders redirect you from one cell to another. From cell c, roll 1-6 and land on c+roll (or its redirect). Find minimum dice rolls to reach n*n from 1.
Approach
Minimum dice rolls to reach end of snake-and-ladder board (BFS on game states).
Input
6x6 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
More Queues problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards