Data Structures & AlgorithmsVery hardCodeforces Div2 D · TCS NQT

Delete at most ONE element from [1, 3, 2, 5, 4, 6, 9, 7, 8] (or none). What is the length of the longest strictly increasing subsequence of what remains?

  1. A. 6
  2. B. 7
  3. C. 9
  4. D. 3

Correct answer: A. 6

Combine prefix and suffix LIS with a skip at each index, or rerun LIS per deletion: the best is 6 (e.g. 1, 2, 4, 6, 7, 8), the same as with no deletion. Assuming a deletion always adds one gives 7, 9 is the array length and 3 is the longest increasing contiguous run.

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

Exams that ask this topic