Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2
Array A = [4, 3, 9, 3, 3, 9, 7] (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 9.
- A. 128
- B. 2
- C. 3
- D. 14
Correct answer: C. 3
Enumerating all subsets of indices gives 3 with sum 9. Allowing each value to be reused, as in the coin-change count, gives 2.
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
- Distinct words ['aa', 'ab', 'ca', 'c', 'bb'] are inserted into an empty trie (one node per character, shared prefixes share nodes, and a…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (1), A–C (1), A–E (1), B–C (2), B–D (3), C–E (1), D–E (3). How many…
- Directed weighted graph on vertices A, B, C, D, E with edges (u→v, w): C→D (8); E→C (4); D→C (8); C→E (6); D→A (4); B→E (5). Let d(x, y)…
- Weighted tree on vertices 0 to 5 with edges 0–1 (9), 0–2 (8), 1–3 (4), 3–4 (4), 1–5 (3). What is the largest possible sum of edge weights…
- A binary tree with distinct letters has preorder DFEACB and inorder FDACEB. What is its postorder traversal (left, right, root), written…
- 5 × 5 grid, rows top to bottom ('#' = wall, '.' = open): ..... / ###.. / ....# / ...## / ##.#.. Start at top-left, target bottom-right…