Data Structures & AlgorithmsHardCodeforces Div2 B · TCS NQT
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, 1, 5, 2] strictly increasing (a[i] < a[i+1] for every i)?
- A. 3
- B. 5
- C. 15
- D. 7
Correct answer: D. 7
Scan left to right and raise each element to exactly one more than the previous (never lower anything). Making the array only non-decreasing needs fewer operations, which is the wrong target here.
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
- 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…
- In how many ways can a 2 × 9 board be tiled exactly with 2 × 1 dominoes (placed vertically) and 2 × 2 squares, with no overlaps and no…
- How many integers x with 1 ≤ x ≤ 1000 are perfect squares or perfect cubes (or both)?
- Intervals (inclusive integer ranges) are [(1, 3), (2, 5), (4, 9), (6, 7), (8, 12), (9, 10)]. What is the minimum number of intervals whose…
- A binary string is "10110010". Flipping position i costs weight[i] = [3, 1, 4, 1, 5, 9, 2, 6]. You want the string to alternate (0101…
- How many contiguous subarrays of the binary array [1, 0, 1, 1, 0, 0, 1, 0] contain equally many 0s and 1s? (Non-empty subarrays only.)