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].
- A. 106
- B. 15
- C. 102
- 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
- Problem: How many subsets of {1, 2, ..., 8} contain no two consecutive integers (the empty set counts)?
- Problem: How many ways can the total 10 be formed as an unordered multiset of parts chosen from {1, 2, 3, 5} (repetition allowed)?
- Problem: A 3×3 matrix is [[2,1,3],[6,5,4],[7,8,9]]. A falling path moves from a cell in row r to a cell in row r+1 in the same column or…
- Problem: Video clips of the form [start, end] cover the interval [0, 10]. The clips are [0,2], [4,6], [8,10], [1,9], [2,5], [5,7]. What is…
- Problem: The stock span of a day is the number of consecutive days (including today) up to and including today with a price at most…
- Problem: Five customers with service times 5, 3, 8, 2, 4 (in arrival order) are served by two tellers. Each customer goes to whichever…