Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
Starting at index 0 of [1, 2, 1, 1, 1], each a[i] is the maximum forward jump. What is the minimum number of jumps needed to reach the last index?
- A. 4
- B. 2
- C. 5
- D. 3
Correct answer: D. 3
The minimum jumps follow the BFS layers of the reachable range. The jumps 0 to 1, then 1 to 3, then 3 to 4 reach the end in 3 jumps.
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
- What is the length of the longest contiguous substring of "([)][]()[[]]" that is a balanced bracket sequence, where '(' must close with…
- How many contiguous substrings of "(()())(())((()))" are balanced round-bracket sequences whose maximum nesting depth is at most 2?
- What is the length of the longest contiguous substring of "xxyxyyxyxxy" in which the number of 'x' letters is at most the number of 'y'…
- Sort 4 7 4 2 7 2 9 4 3 so that values with higher FREQUENCY come first; values with equal frequency are ordered by value ascending, and…
- In the sorted array 1 1 1 2 2 3 3 3 3 4, remove the extra copies so that every value appears AT MOST TWICE, keeping the order. What is the…
- In the string "abciiidefoeuxyz", what is the largest number of vowels (a, e, i, o, u) that appear in any contiguous window of length 3?