Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band
Array A = [2, 3, 3, 4, 2, 2, 3, 5, 2]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly increasing). How many index sets give an increasing subsequence of the maximum possible length?
- A. 15
- B. 1
- C. 4
- D. 2
Correct answer: D. 2
The longest strictly increasing subsequence has length 4, and there are 2 index sets achieving it. Counting distinct value sequences merges equal choices, which is the trap here.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A trie keeps a counter at each node, and every word of the list W = ['ab', 'cc', 'ba', 'ca', 'ac', 'ba', 'cba', 'bba'] is inserted once…
- Connected undirected graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–E (1), A–F (1), B–E (1), B–F (1), C–D (1), D–F (1), D–G…
- Connected undirected weighted graph on vertices A, B, C, D, E, F with edges A–B (1), A–C (14), A–F (12), B–D (12), C–D (8), C–E (1), E–F…
- Directed acyclic graph on vertices A, B, C, D, E, F, G (every edge goes from a smaller to a larger letter) with weighted edges A→E (8)…
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…
- Directed weighted graph on vertices A, B, C, D, E with edges listed in this exact order: C→A (3); E→C (7); B→C (-2); B→D (6); A→B (5); C→E…