Data Structures & AlgorithmsVery hardCodeforces Div2 C · ICPC regional
In one operation you may choose a contiguous subarray and increase every element in it by 1. Starting from [0, 0, 0, 0], what is the minimum number of operations needed to reach [3, 1, 2, 4]?
- A. 10
- B. 6
- C. 4
- D. 8
Correct answer: B. 6
The minimum number of range increments to build a target from zeros is the sum of the positive jumps t[i] − t[i−1] (with t[0] counted from zero). Summing the values, or taking the maximum, counts the same increment many times.
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 contiguous subarrays of [1, 2, 1, 3, 3, 2, 4, 1] contain EXACTLY 2 distinct values?
- Evaluate 3 + 5 2 - 8 / 4 using standard precedence and integer division. What is the result?
- The exponent operator ^ is right-associative. What is the value of 2 ^ 3 ^ 2?
- How many valid (balanced) bracket sequences of length 8 are there using one type of bracket?
- A grid has the rows ..#.., .##.., ....., #.#.# (where '.' is open and '#' is a wall; all rows have length 5). Starting from the top-left…
- A list holds 1, 1, 2, 2, 2, 3, 1, 1. Consecutive duplicates are merged into one node each. What is the sum of the values left in the list?