Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6454 |

@blackshadows | 6380 |

@mb1973 | 5718 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3709 |

@mantu_singh | 3556 |

@marius_valentin_dragoi | 3523 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1285 |

@gurshehzadsingh | 1052 |

@pritsahkar2000 | 812 |

@satyamchhatrala | 808 |

@nithinreddy3210 | 801 |

@iib2019024 | 745 |

@mohanreddy8847 | 704 |

@iamchaitanyahegde | 662 |

@shafeeq3543 | 651 |

@workit | 646 |

@AkashLahoty | 642 |

Complete Leaderboard |

Given a **5x6** snakes and ladders board, find the minimum number of dice throws required to reach the destination or last cell (**30 ^{th}** 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

**Example 1:**

**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 shown
in 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.

**Your Task:**

You do not need to read input or print anything. Your task is to complete the function **minThrow()** which takes **N** and **arr** as input parameters and returns the minimum number of throws required to reach the end of the game.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(N)

**Constraints:**

1 ≤ N ≤ 10

1 ≤ arr[i] ≤ 30

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Snake and Ladder Problem

...