Data Structures & AlgorithmsHardCodeforces Div2 C · LeetCode-style
Positions 0 to 9 form a line. Cells marked 1 are blocked, the rest are free. From a cell you may jump forward by at most 3 positions (to any free cell in that range). Starting at 0, what is the minimum number of jumps to reach the last cell, or −1 if impossible?
- A. 5
- B. 3
- C. 4
- D. 6
Correct answer: C. 4
BFS or a DP over cells: dist[i] = 1 + min dist[j] over free j within k steps behind i, with blocked cells unreachable. Jumping greedily to the farthest free cell can be impossible because of blocks.
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
- Positions [15, 3, 22, 9, 40, 27] are given in arbitrary order. What is the largest difference between two consecutive positions when the…
- How many subsets (chosen by position, the empty subset included) of [6, 1, 3, 5, 2] have a bitwise XOR equal to 4?
- What is the length of the shortest contiguous subarray of [2, -1, 2, 3, -4, 5, 1] whose sum is at least 6? Negative numbers are present…
- A sorted array of distinct values was rotated some number of times. Which technique finds the minimum element in O(log n) time, and why…
- In one operation you may increase any single element by 1. What is the minimum total number of operations needed to make the array [1, 1…
- Choose two NON-OVERLAPPING non-empty contiguous subarrays of [4, -1, 2, 6, -3, 5, -2] (the first must end before the second starts) and…