If you are a c# beginner or want to start learning the c# programming language, then this program will help you to understand the basics of c# programming. In this program, we are going to share the C# program to find Minimum number of jumps to reach end with the output.
Copy the below c# program and execute it in your Microsoft Visual Studio IDE (Integrated Development Environment ). At the end of this program, I have shared the output program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
using System; class MinimumOrderOfJump { static int minJumps(int []arr, int l, int h) { if (h == l) return 0; if (arr[l] == 0) return int.MaxValue; int min = int.MaxValue; for (int i = l+1; i <= h && i <= l + arr[l]; i++) { int jumps = minJumps(arr, i, h); if(jumps != int.MaxValue && jumps + 1 < min) min = jumps + 1; } return min; } public static void Main() { int []arr = {1, 3, 6, 3, 2, 3, 6, 8, 9, 5}; int n = arr.Length; Console.Write("Minimum number of jumps to reach end is " + minJumps(arr, 0, n-1)); } } |
Minimum number of jumps to reach end is 4
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.