Data Structures & AlgorithmsHardICPC regional · Product Company SDE

Problem: Find the maximum sum of a strictly increasing subsequence of [1, 101, 2, 3, 100, 4, 5].

  1. A. 106
  2. B. 15
  3. C. 102
  4. D. 216

Correct answer: A. 106

dp[i] = a[i] + max dp[j] over j < i with a[j] < a[i]: 1 + 2 + 3 + 100 = 106. The sum of the LONGEST increasing subsequence 1, 2, 3, 4, 5 is only 15, greedily taking 101 gives 102, and 216 adds every element.

More Coding Interview Problems questions

Exams that ask this topic