Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Words ['abd', 'bd', 'dac', 'cac', 'dcb', 'dab', 'dcc'] (each may be used at most once). A chain is a sequence of these words in which the first letter of every word after the first equals the last letter of the word before it. What is the largest number of words in any chain?
- A. 3
- B. 4
- C. 7
- D. 5
Correct answer: D. 5
Bitmask DP over subsets gives 5. Greedily taking the first matching word from the list stops at 3, which is the trap for this question.
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, F with edges A–B (14), A–C (14), A–D (6), A–E (3), B–C (16), B–D (20), B–E…
- Undirected weighted graph on vertices A, B, C, D, E, F with edges A–C (6), A–D (9), A–E (3), A–F (6), B–C (7), B–E (3), B–F (3), D–F (3)…
- Directed acyclic graph on vertices A, B, C, D, E with edges A→C, A→E, E→B. Among all topological orderings (every edge goes from earlier…
- Distinct keys [6, 20, 4, 25, 16] are inserted, in the order given by the sequence [16, 25, 20, 6, 4], into an empty binary search tree…
- Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–F (1), A–G (1), B–C (1), B–G (1), C–D (1), C–G (1), E–G (1)…
- Array A = [6, 7, 4, 1, 8, 8, 7] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not…