Data Structures & AlgorithmsVery hardCodeforces Div2 D · ICPC regional
For the array [1, 3, 5, 4, 7, 2, 2, 8, 6, 9], how many DIFFERENT subsequences (chosen by index) are strictly increasing AND have the maximum possible length?
- A. 6
- B. 2
- C. 143
- D. 1
Correct answer: B. 2
Keep a second array counting how many longest increasing subsequences end at each index, and add counts when a predecessor gives the same best length. The length alone does not answer a count question, and counting every increasing subsequence includes short ones.
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
- What is the maximum possible SUM of a strictly increasing subsequence of [1, 101, 2, 3, 100, 4, 5]?
- 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"?