Data Structures & AlgorithmsHardCodeforces Div2 B · Infosys

Array [2, 3, 1, 1, 4, 2, 1, 3, 1, 2]: from index i you may jump to any index in the range i+1 ... i+arr[i]. You start at index 0 and want to reach the last index. What is the minimum number of jumps?

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

Correct answer: B. 4

Scan once and keep the farthest index reachable; each time you reach the end of the current jump window, one more jump is needed. Always taking the single first step toward the end is not optimal.

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

Exams that ask this topic