Data Structures & AlgorithmsVery hardGATE CS
In a jump game, a[i] is the maximum jump length from index i (any length from 1 to a[i] is allowed). For a = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4], what is the minimum number of jumps needed to go from index 0 to the last index?
- A. 4
- B. 5
- C. 6
- D. 3
Correct answer: A. 4
A BFS or greedy window expansion gives 4. Always jumping the maximum allowed distance can skip better landing cells.
More Coding Interview Problems questions
- The sequence a1, ..., a14 is generated by a1 = 1 and a(i+1) = (5a(i) + 3) mod 17. How many pairs (i, j) with i < j satisfy a(i) > a(j)?
- In how many ways can 30 be written as a sum of distinct positive integers, each at most 10, if the order of the summands does not matter?
- An undirected weighted graph on vertices 0-5 has edges (u, v, w): (0,1,2), (0,2,2), (1,3,3), (2,3,3), (1,4,5), (2,4,5), (3,5,1), (4,5,1)…
- Problem: A delivery app logs the parcel weights of a day in an array. Return the indices of the two parcels whose weights add up exactly…
- Problem: Given an unsorted array of n ≤ 10⁵ integers and a target, report whether two different positions hold values summing to the…
- Problem: A stock tracker gets daily prices and must report the best profit from one buy followed by one later sell (0 if no profit is…