Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2
Words ['dd', 'da', 'bb', 'bd', 'db', 'cc', 'aba'] (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. 6
- C. 4
- D. 7
Correct answer: B. 6
Bitmask DP over subsets gives 6. 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
- Undirected weighted graph on vertices A, B, C, D, E with edges A–D (2), A–E (1), B–C (2), C–D (1), C–E (3), D–E (2). An edge is CRITICAL…
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (1), A–D (2), B–C (1), B–D (6), B–E (3), C–E (1). Among all…
- Directed weighted graph on vertices A, B, C, D, E with edges listed in this exact order: D→A (3); B→A (2); E→A (-3); A→B (3); D→E (4); A→D…
- Keys are inserted in the order 32 20 62 89 57 42 59 into an empty binary search tree. Then the key 32 (which has two children) is deleted…
- Array A = [31, 12, 22, 25, 21, 10, 0, 20, 9]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 25? (A trie with subtree counts answers…
- A binary trie of 6-bit numbers stores the set S = [63, 33, 9, 22, 26, 2, 29]. For the query x = 24, what is the maximum value of x XOR s…