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?
- A. 3
- B. 1
- C. 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.
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
- There are 100 bulbs, all off. For each i from 1 to 100, pass i toggles every bulb whose number is a multiple of i. How many bulbs are on…
- What is the smallest positive integer x such that 180 x is a perfect cube?
- How many trailing zeros does 100! have when written in base 6?
- What is the sum of all distinct prime factors of the product 12 35 49 (sum each prime once, however many times it divides the product)?
- What is the lexicographically smallest string obtainable by deleting exactly one character from cbabc?
- How many length-3 windows of the string aabxaaba have at most one position that differs from the pattern aab?