Data Structures & AlgorithmsVery hard

In the jump game (minimum number of jumps), why does a single left-to-right scan with a 'current boundary' count the jumps correctly?

  1. A. Each time the scan reaches the boundary of the current jump level, one more jump is needed and the boundary extends to the furthest index reachable so far.
  2. B. Every element is a jump of length one, so the count is the array length.
  3. C. The scan must restart from index 0 after each jump.
  4. D. The jumps are the same as the number of zeros in the array.

Correct answer: A. Each time the scan reaches the boundary of the current jump level, one more jump is needed and the boundary extends to the furthest index reachable so far.

The set of indices reachable in k jumps is a prefix of the array, so the furthest reach at each level determines the next level. This gives the minimum number of levels in a single pass.

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

Exams that ask this topic