• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
January 17, 2024 |1.2K Views
SDE Sheet - Snake and Ladder Problem
  Share  1 Like
Description
Discussion

This video is part of Graph section under GFG SDE Sheet.

In this problem, we are given  a 5x6 snakes and ladders board, find the minimum number of dice throws required to reach the destination or last cell (30th cell) from the source (1st cell).

You are given an integer N denoting the total number of snakes and ladders and an array arr[] of 2*N size where 2*i and (2*i + 1)th values denote the starting and ending point respectively of ith snake or ladder. The board looks like the following.
Note: Assume that you have complete control over the 6 sided dice. No ladder starts from 1st cell.

Example :

Input:
N = 8
arr[] = {3, 22, 5, 8, 11, 26, 20, 29, 
      17, 4, 19, 7, 27, 1, 21, 9}
Output: 3
Explanation:
The given board is the board shownin the figure. For the above board output will be 3. 
a) For 1st throw get a 2. 
b) For 2nd throw get a 6.
c) For 3rd throw get a 2.

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-
Article: https://www.geeksforgeeks.org/snake-ladder-problem-2/
Problem: https://www.geeksforgeeks.org/problems/snake-and-ladder-problem4816/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More