Data Structures & AlgorithmsHard
Starting at index 0 of 2 3 1 1 4 2 3 1 1 4, a value a[i] lets you jump from index i to any index in i+1 … i+a[i]. What is the minimum number of jumps needed to reach the LAST index?
- A. 5
- B. 13
- C. 3
- D. 4
Correct answer: D. 4
Track the furthest index reachable within the current number of jumps; when you reach the boundary of the current level, the count goes up by one. A +1 on top of the level count, or reporting the furthest index itself, misreads the rule.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Remove duplicate values from the unsorted list 4 2 4 1 2 5 1 so that only ONE copy of each value remains, keeping the copy that appears…
- A single stack, starting empty, is used to sort the input permutation of 1..4 into 1, 2, 3, 4 at the output (each input element is pushed…
- Two sorted lists A = 10 30 50 and B = 5 40 60 80 90 are merged by taking nodes ALTERNATELY (first from A, then from B, and so on) until…
- From the array 3 -1 8 2 -4 6 5 you may take exactly 3 elements, each taken from the LEFT end or from the RIGHT end of what remains. What…
- In one operation you increase ALL elements of the array 1 2 4 except one chosen element by 1. What is the minimum number of operations…
- A stream arrives one character at a time: a a b c b d. After each character, report the FIRST character (in arrival order) that has…