Data Structures & AlgorithmsVery hardCodeforces Div2 C · ICPC regional

What is the minimum possible length of a single CONTIGUOUS block of [1, 3, 7, 4, 2, 5, 9] that you can delete (the rest is concatenated in order) so that the remaining array is non-decreasing? An empty deletion is not allowed.

  1. A. 4
  2. B. 3
  3. C. 2
  4. D. 5

Correct answer: B. 3

Two pointers from the sorted prefix and sorted suffix: find the longest non-decreasing prefix and suffix that can be joined, then delete the gap between them. Deleting only from one end, or greedily removing the first descent, misses the cheapest block.

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

Exams that ask this topic