Data Structures & AlgorithmsModerateCodeforces Div2 B-D · ICPC regional
Minimum number of elements to delete from [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] so the remaining sequence is non-decreasing (equal neighbours allowed)?
- A. 6
- B. 7
- C. 11
- D. 2
Correct answer: A. 6
Deletions = n − longest non-decreasing subsequence = 11 − 5 (e.g. 1, 1, 2, 3, 5). Patience sorting must use bisect_right so equal values can extend the chain; bisect_left finds a strictly increasing length of 4 and gives 7.
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 index pairs i < j satisfy a[i] > 2 a[j] for a = [5, 1, 3, 9, 2, 8, 4]?
- How many contiguous subarrays of [2, 4, 3, 1, 5, 7, 6] consist of consecutive integers (all distinct, with max minus min equal to length…
- What is the length of the longest contiguous subarray of [1, 2, 4, 3, 6, 8, 5, 7] whose sum is even?
- Choose two disjoint contiguous windows of length exactly 2 in [1, 2, 9, 4, 5, 1, 8, 3] (the windows may not share an index). What is the…
- What is the maximum product over all non-empty contiguous subarrays of [2, 3, -2, 4, -1, -5, 0, 2]?
- How many distinct values in [3, 3, 4, 2, 4, 4, 2, 4, 4] occur strictly more than n/3 times (n = 9)?