Data Structures & AlgorithmsHard
Each operation increases one element of 3 3 1 6 2 by 1. What is the minimum total number of operations to make the array STRICTLY increasing?
- A. 10
- B. 11
- C. 9
- D. 3
Correct answer: A. 10
Greedily keep each element at least one more than the previous one, raising it only when needed; this minimizes the total raise. Overshooting the target by one, a missing step, or counting violations instead of the raise cost each give a different value.
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
- Using AT MOST ONE swap of two elements, what is the lexicographically smallest array obtainable from 3 1 2 5 4?
- How many contiguous subarrays of 3 1 4 1 5 9 2 6 contain the position of the global maximum value 9?
- For each contiguous window of size 3 in 4 2 12 3 8 1 7, take its minimum. What is the largest of these window minimums?
- For every contiguous window of size 3 in 4 2 12 3 8 1 7, take its minimum and add all these minimums. What is the total?
- How many contiguous windows of length exactly 4 in 2 5 1 0 3 4 2 6 have a sum strictly less than 10?
- What is the length of the longest contiguous subarray of 3 4 4 5 3 2 6 6 7 in which every two elements differ by at most 1, i.e. max − min…