Data Structures & AlgorithmsVery hardCodeforces Div2 C
For the array [3, -7, 4, -2, 5, -9, 6, 1], you may delete at most ONE element (the rest keep their order). Then you take a non-empty contiguous subarray of what remains. What is the largest possible sum?
- A. 14
- B. 7
- C. -2
- D. 13
Correct answer: A. 14
Track two states while scanning: the best sum ending here with no deletion used, and the best sum ending here where exactly one element has been dropped. Plain Kadane ignores the deletion, and skipping the state that starts right after the deleted element misses the best segment.
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
- 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…
- 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.