Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT
A frog at position 0 wants to land exactly on position 17. Each jump has length 3, 5 or 7. What is the minimum number of jumps needed, or −1 if it is impossible?
- A. 3
- B. 4
- C. 5
- D. 2
Correct answer: A. 3
This is the coin-change minimum with coins {3, 5, 7}: d[v] = 1 + min d[v − s]. Greedy by the largest jump that fits (7 + 7 + 3) gives 3 jumps for 17, which happens to be optimal only by luck, so the DP is the safe method.
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
- How many binary strings of length 8 have every maximal run of equal digits of length at least 2?
- How many contiguous subarrays of [1, 2, 1, 3, 4, 2, 5] of length at least 2 consist of pairwise distinct values?
- For the array [7, 3, 9, 3, 5, 9, 1, 7], what is the maximum value of (j − i) over pairs of positions i < j with a[i] = a[j]?
- What is the length of the longest contiguous block of [2, 3, 5, 4, 6, 7, 8, 1, 2, 3] in which every element is strictly larger than the…
- A frog starts on stone 0 with heights [10, 30, 40, 20, 25, 10]. It can jump to stone i+1 or i+2, and the cost of a jump is the absolute…
- Grid [[3, 1, 4, 1], [5, 9, 2, 6], [5, 3, 5, 8], [9, 7, 9, 3]]. Starting from any cell in the top row, each step goes to the cell directly…