Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Array A = [5, 3, 5, 3, 2, 2, 4, 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. 2
- B. 9
- C. 3
- D. 13
Correct answer: B. 9
The longest strictly increasing subsequence has length 2, and there are 9 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
- Undirected weighted graph on vertices A, B, C, D, E; its edges, in this listed order, are: A–C (1), B–C (8), B–D (5), D–E (6), C–E (7)…
- Consider the recursive function def f(n): if n < 3: return 1; return f(n-1) + f(n-3). Evaluate f(9) and count every invocation of f…
- A binary tree with distinct letters has preorder DAEFCB and inorder EADCFB. What is its postorder traversal (left, right, root), written…
- Connected undirected graph on vertices A, B, C, D, E, F with edges A–C (1), A–D (1), A–E (1), A–F (1), B–D (1), E–F (1) (weights ignored)…
- 5 × 4 grid, rows top to bottom ('#' = blocked, '.' = open): ..#. / ...# / ...# / ..#. / ..... Count the paths from top-left to…
- Undirected graph on vertices A, B, C, D, E, F with edges, in this exact order: B–D (1), A–D (1), B–F (1), C–D (1), D–F (1), B–E (1)…