adplus-dvertising
frame-decoration

Question

What is the output of the following program?
#include<stdio.h>
#include<limits.h>
int min_jump(int *arr, int len)
{
      int j, idx, jumps[len];
      jumps[len - 1] = 0;
      for(idx = len - 2; idx >= 0; idx--)
      {	
	  int tmp_min = INT_MAX;
	  for(j = 1; j <= arr[idx] && idx + j < len; j++)
	  {
	        if(jumps[idx + j] + 1 < tmp_min)
		  tmp_min = jumps[idx + j] + 1;
	  }
	  jumps[idx] = tmp_min;
      }
      return jumps[0];
}
int main()
{
      int arr[] ={9, 9, 9, 9, 9, 9, 9, 9, 9},len = 9;
      int ans = min_jump(arr,len);
      printf("%d\n",ans);
      return 0;
}

a.

1

b.

6

c.

2

d.

7

Answer: (a).1

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of the following program?

Similar Questions

Discover Related MCQs

Q. The Knapsack problem is an example of ____________

Q. Which of the following methods can be used to solve the Knapsack problem?

Q. You are given a knapsack that can carry a maximum weight of 60. There are 4 items with weights {20, 30, 40, 70} and values {70, 80, 90, 200}. What is the maximum value of the items you can carry using the knapsack?

Q. Which of the following problems is equivalent to the 0-1 Knapsack problem?

Q. What is the time complexity of the brute force algorithm used to solve the Knapsack problem?

Q. The 0-1 Knapsack problem can be solved using Greedy algorithm.

Q. Which of the following methods can be used to solve the matrix chain multiplication problem?

Q. Which of the following is the recurrence relation for the matrix chain multiplication problem where mat[i-1] * mat[i] gives the dimension of the ith matrix?

Q. Consider the two matrices P and Q which are 10 x 20 and 20 x 30 matrices respectively. What is the number of multiplications required to multiply the two matrices?

Q. Consider the matrices P, Q and R which are 10 x 20, 20 x 30 and 30 x 40 matrices respectively. What is the minimum number of multiplications required to multiply the three matrices?

Q. Consider the matrices P, Q, R and S which are 20 x 15, 15 x 30, 30 x 5 and 5 x 40 matrices respectively. What is the minimum number of multiplications required to multiply the four matrices?

Q. Consider the brute force implementation in which we find all the possible ways of multiplying the given set of n matrices. What is the time complexity of this implementation?

Q. Which of the following methods can be used to solve the longest common subsequence problem?

Q. Consider the strings “PQRSTPQRS” and “PRATPBRQRPS”. What is the length of the longest common subsequence?

Q. Which of the following problems can be solved using the longest subsequence problem?

Q. Longest common subsequence is an example of ____________

Q. What is the time complexity of the brute force algorithm used to find the longest common subsequence?

Q. Which of the following is the longest common subsequence between the strings “hbcfgmnapq” and “cbhgrsfnmq” ?

Q. Which of the following methods can be used to solve the longest palindromic subsequence problem?

Q. Which of the following strings is a palindromic subsequence of the string “ababcdabba”?