Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band
Words ['aad', 'cda', 'bb', 'aaa', 'cbc', 'cdb'] (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. 6
- B. 4
- C. 1
- D. 2
Correct answer: B. 4
Bitmask DP over subsets gives 4. Greedily taking the first matching word from the list stops at 1, 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
- Words ['aa', 'acb', 'caa', 'caa', 'cbba', 'c'] are inserted in this order into an empty trie with one node per character, shared prefixes…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (2), A–C (3), A–D (3), B–D (3), C–E (3), D–E (2). An edge is CRITICAL…
- 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…
- 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…