Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Array A = [9, 8, 3, 6, 4, 2, 6] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not ordered) whose values add up to exactly 20.
- A. 72
- B. 1739
- C. 6
- D. 128
Correct answer: C. 6
Enumerating all subsets of indices gives 6 with sum 20. Allowing each value to be reused, as in the coin-change count, gives 1739.
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 weighted graph on vertices A, B, C, D, E with edges A–B (12), A–C (1), A–E (10), B–D (18), B–E (13), C–D (13), D–E…
- Words ['aaac', 'bac', 'cb', 'ac', 'baab', 'bc', 'bac'] are inserted in this order into an empty trie with one node per character, shared…
- Directed graph on vertices A, B, C, D, E, F with edges F→C, B→A, C→F, D→B, B→F, A→E, E→F, A→C, B→D (no weights). What is the number of…
- Array A = [3, 4, 4, 1, 1, 4, 5, 5]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- Directed graph on vertices A, B, C, D, E, F, G with edges E→B, D→A, C→A, B→E, C→B, F→A, E→D, G→B, B→F, F→G. How many strongly connected…
- Keys [20, 43, 1, 35, 37, 18, 49] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right…