-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathcode_1.cpp
More file actions
43 lines (37 loc) · 845 Bytes
/
code_1.cpp
File metadata and controls
43 lines (37 loc) · 845 Bytes
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
34
35
36
37
38
39
40
41
42
43
//
// code_1.cpp
// Algorithm
//
// Created by Mohd Shoaib Rayeen on 23/11/18.
// Copyright © 2018 Shoaib Rayeen. All rights reserved.
//
#include <iostream>
using namespace std;
int minJumps(int arr[], int l, int h) {
if (h == l) {
return 0;
}
if (arr[l] == 0) {
return INT_MAX;
}
int min = INT_MAX;
for (int i = l + 1; i <= h && i <= l + arr[l]; i++) {
int jumps = minJumps(arr, i, h);
if(jumps != INT_MAX && jumps + 1 < min) {
min = jumps + 1;
}
}
return min;
}
int main() {
int n;
cout << "\nEnter Size\t:\t";
cin >> n;
int array[n];
cout << "\nEnter Array Elements\n";
for ( int i = 0 ;i < n;i++) {
cin >> array[i];
}
cout << "\nMinimum Jumps\t:\t" << minJumps(array, 0, n-1) << "\n";
return 0;
}