What will be the output of the following code? [code] #include <bits/stdc++.h> using namespace std; int func(int arr[], int s, int e)

What will be the output of the following code?
Code:
#include <bits/stdc++.h> 
using namespace std; 
int func(int arr[], int s, int e) 
{
   if (s == e) 
	return 0; 
   if (arr[s] == 0) 
	return INT_MAX; 
int min = INT_MAX; 
for (int i = s + 1; i <= e &#038;&#038; i <= s + arr[s]; i++) 
{ 
	int jumps = func(arr, i, e); 
	if(jumps != INT_MAX &#038;&#038; jumps + 1 < min) 
		min = jumps + 1; 
} 
return min; 
}
int main() 
{ 
	int arr[] = {1, 3, 6, 3, 8, 5}; 
	int n = sizeof(arr)/sizeof(arr[0]); 
	cout << func(arr, 0, n-1); 
	return 0; 
}
A. 1
B. 2
C. 3
D. error
 

Tìm kiếm

Back
Top