GATE Computer ScienceHardGATE CS (PYQ pattern)
From index 0 of the array [3, 1, 4, 1, 2, 1, 1, 5, 2, 1, 1, 3, 1, 2, 1] you may jump forward at most a[i] positions from index i. What is the minimum number of jumps to reach the last index?
- A. 4
- B. 6
- C. 5
- D. 7
Correct answer: C. 5
A DP d[j] = min over reachable i of d[i] + 1 gives d[14] = 5 (one optimal route is the indices 0 → 2 → 6 → 7 → 11 → 14). The greedy farthest-reach scan finds the same value.
More Algorithms questions
- The array [12, 7, 9, 14, 5, 11, 8, 10, 6] must be split into 3 contiguous parts so that the largest part sum is as small as possible. What…
- Coupons of 6 equally likely types are drawn with replacement. What is the expected number of draws until 4 different types have been seen?
- Counting sort (stable, processing the input from right to left with cumulative counts) is applied to a = [4, 2, 2, 8, 3, 3, 1, 4, 2]. At…
- LSD radix sort (decimal digits, stable counting sort on each digit, least significant first) is applied to [329, 457, 657, 839, 436, 720…
- A shell sort pass with gap 5 (a gapped insertion sort) is applied to [23, 12, 45, 3, 67, 8, 34, 19, 56, 2, 41, 28]. The cost of the pass…
- The array [14, 5, 21, 9, 30, 7, 18, 2, 26, 11] is made into a max-heap, giving [30, 26, 21, 14, 11, 7, 18, 2, 9, 5]. Heapsort then…