Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2
Array A = [3, 1, 2, 3, 4, 1, 4, 1, 4]. 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. 21
- B. 3
- C. 1
- D. 4
Correct answer: B. 3
The longest strictly increasing subsequence has length 4, and there are 3 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
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–D (1), B–F (1), B–H (1), C–D (1), D–E (1), D–H (1), E–G (1)…
- Weighted tree on vertices 0 to 6 with edges 0–1 (7), 1–2 (8), 0–3 (7), 0–4 (2), 0–5 (1), 1–6 (8). What is the largest possible sum of edge…
- Directed graph on vertices 0 to 4 with weighted edges (u→v (w)); some weights are negative: 0→4 (8), 1→4 (-1), 0→1 (6), 3→1 (-2), 0→3 (7)…
- Directed graph on vertices 0 to 4 with weighted edges (u→v (w)); some weights are negative: 2→3 (-2), 1→3 (3), 0→1 (1), 0→4 (7), 1→0 (-1)…
- Directed graph on vertices 0 to 4 with weighted edges (u→v (w)); some weights are negative: 1→4 (0), 3→0 (3), 0→1 (-2), 2→3 (2), 2→1 (-1)…
- Directed graph on vertices 0 to 5 with weighted edges (u→v (w)); some weights are negative: 3→5 (1), 2→1 (2), 5→1 (4), 1→3 (-2), 1→2 (2)…