Data Structures & AlgorithmsVery hardCodeforces Div2 D · GATE CS
Choose a subsequence of length exactly 3 from [5, 1, 4, 2, 6, 3, 7, 2] (keeping order) whose elements are non-decreasing. What is the maximum possible sum?
- A. 13
- B. 20
- C. 18
- D. 19
Correct answer: C. 18
Use a DP over (index, length) with the non-decreasing constraint, taking the best predecessor with a smaller or equal value. Choosing the k largest values ignores the order requirement.
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
- How many DIFFERENT palindromic strings of length 3 occur as subsequences of "abcbaab" (each string counted once, however many index…
- Deleting exactly one character from "110100" gives a new binary string each time. How many DISTINCT strings result?
- How many DISTINCT palindromic strings (of any length ≥ 1) occur as subsequences of "abab"?
- Count the index paths from position 0 to position 6 in the array [1, 3, 2, 4, 6, 5, 7] where each move goes from index i to a LATER index…
- A binary partition of 20 is a way to write 20 as a sum of powers of two (1, 2, 4, 8, ...), where order does not matter and repeats are…
- On a 1 × 9 strip of cells, you place 3 non-overlapping dominoes, each covering two adjacent cells. Two dominoes may not share a cell. How…