Data Structures & AlgorithmsHardGATE CS · ICPC regional

An array [2, 3, 1, 1, 4] gives the maximum forward jump from each index. Starting at index 0, what is the minimum number of jumps needed to reach the last index?

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

Correct answer: D. 2

A greedy or BFS layer approach works: each layer is the set of indices reachable with the same number of jumps. Jumping to the farthest reachable index at each step is optimal here.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic