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]?
- A. 5
- B. 216
- C. 106
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- The longest bitonic subsequence of an array is a subsequence that first strictly increases and then strictly decreases (either part may be…
- A pair (a, b) can follow pair (c, d) in a chain when b < c. The pairs are [(5, 24), (39, 60), (15, 28), (27, 40), (50, 90), (1, 2), (3…
- What is the minimum number of elements you must DELETE from [9, 4, 7, 2, 10, 3, 8, 11, 5] (the rest keep their order) so that the…
- What is the length of the longest common subsequence of the strings "AGGTABQZ" and "GXTXAYBZQ"?
- What is the length of the longest common SUBSTRING (contiguous) of "ABABCABBAC" and "BABCBACAB"?
- What is the minimum number of single-character insertions, deletions and substitutions needed to turn "sunday" into "saturnday"?