Data Structures & AlgorithmsVery hard

The minimum number of consecutive deletions to make an array non-decreasing is found by which structure?

  1. A. The longest decreasing subsequence.
  2. B. A non-decreasing prefix joined to a non-decreasing suffix, with two pointers matching the junction.
  3. C. The sum of all descents.
  4. D. Sorting the array and counting differences.

Correct answer: B. A non-decreasing prefix joined to a non-decreasing suffix, with two pointers matching the junction.

The kept elements form a non-decreasing prefix followed by a non-decreasing suffix whose junction is compatible. Two pointers find the widest compatible pair of prefix and suffix, and the deleted block is the gap between them.

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

Exams that ask this topic