Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

What is the maximum possible SUM of a strictly increasing subsequence of [1, 101, 2, 3, 100, 4, 5]?

  1. A. 5
  2. B. 216
  3. C. 106
  4. D. 101

Correct answer: C. 106

Replace the LIS recurrence by dp[i] = a[i] + max(dp[j]) over j < i with a[j] < a[i]. The length-based LIS picks a different subsequence (here 1, 2, 3, 4, 5), which has a much smaller sum.

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

Exams that ask this topic