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)?

  1. A. 6
  2. B. 7
  3. C. 11
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic