Data Structures & AlgorithmsVery hardGATE CS

In a jump game, a[i] is the maximum jump length from index i (any length from 1 to a[i] is allowed). For a = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4], what is the minimum number of jumps needed to go from index 0 to the last index?

  1. A. 4
  2. B. 5
  3. C. 6
  4. D. 3

Correct answer: A. 4

A BFS or greedy window expansion gives 4. Always jumping the maximum allowed distance can skip better landing cells.

More Coding Interview Problems questions

Exams that ask this topic