Data Structures & AlgorithmsModerate

What is the minimum number of CONSECUTIVE elements you must delete from 1 2 6 3 4 1 5 so that the remaining elements are in non-decreasing order?

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

Correct answer: B. 4

Keep a non-decreasing prefix and a non-decreasing suffix whose junction is also non-decreasing, and remove the gap between them. Counting descents or using the longest sorted run gives different quantities.

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

Exams that ask this topic