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?

  1. A. 4
  2. B. 6
  3. C. 5
  4. 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

Exams that ask this topic