Data Structures & AlgorithmsHardCodeforces Div2 B · Infosys
Array [2, 3, 1, 1, 4, 2, 1, 3, 1, 2]: from index i you may jump to any index in the range i+1 ... i+arr[i]. You start at index 0 and want to reach the last index. What is the minimum number of jumps?
- A. 6
- B. 4
- C. 3
- D. 5
Correct answer: B. 4
Scan once and keep the farthest index reachable; each time you reach the end of the current jump window, one more jump is needed. Always taking the single first step toward the end is not optimal.
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
- You split the array [1, 15, 7, 9, 2, 5, 10] into contiguous non-empty segments, each of length at most 3. A segment contributes (its…
- What is the maximum product of a non-empty contiguous subarray of [-2, 3, -4, 0, -1, 5, -3, -2]?
- How many binary strings of length 12 contain no three consecutive 1s and end with the digit 0?
- Coins of denominations 1, 3 and 4 are available in unlimited supply. What is the minimum number of coins needed to make exactly 6?
- What is the minimum number of perfect squares (1, 4, 9, 16, ...) whose sum is exactly 12? Repeats are allowed.
- Stock prices by day are [3, 3, 5, 0, 0, 3, 1, 4, 9, 2]. You may complete at most TWO buy-then-sell transactions, and you must sell before…