Data Structures & AlgorithmsHardCodeforces Div2 B · TCS NQT
You may increase any element of [5, 3, 2, 10, 4] by any amount (increases only). What is the minimum total increase needed to make the array strictly increasing?
- A. 17
- B. 26
- C. 15
- D. 14
Correct answer: C. 15
Scan left to right and raise each element to exactly one more than the previous value when needed; raising more than necessary only adds cost, and the greedy target is always feasible. Summing all gaps to the maximum does not respect the order constraint.
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
- A path of length 9 is walked from 0 to 9: a step of 1 costs 3 and a step of 2 costs 5. What is the minimum total cost?
- A 1 × 11 strip must be covered exactly by tiles of lengths 2, 3 and 5 (tiles cannot overlap or stick out). Tile lengths 2, 3, 5 cost 4, 5…
- What is the length of the longest CONTIGUOUS block that appears in both arrays [1, 5, 3, 7, 2, 3, 7, 8] and [4, 7, 2, 3, 7, 9, 1] (equal…
- What is the minimum number of letters you must insert (into either string) so that "leetcode" and "codeleet" become anagrams of each other?
- A string of 8 brackets is "]][[][][" where '[' and ']' appear equally often. Each operation swaps any two characters. What is the minimum…
- For each index i of [4, 2, 5, 3, 1, 6], let dist(i) be the distance to the next index j > i with a[j] < a[i] (dist = n − i if no such…