Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Words ['dbd', 'cc', 'bb', 'aca', 'bda', 'ccd'] (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. 2
- D. 1
Correct answer: A. 3
Bitmask DP over subsets gives 3. 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
- Distinct words ['ccc', 'cb', 'ac', 'ba', 'cbb', 'cca'] are inserted into an empty trie (one node per character, shared prefixes share…
- Distinct keys [13, 25, 27, 11, 8, 16] are inserted, in the order given by the sequence [25, 13, 8, 27, 16, 11], into an empty binary…
- Words ['c', 'cbca', 'bbaa', 'a', 'c', 'cca', 'cca'] are inserted in this order into an empty trie with one node per character, shared…
- Undirected graph on vertices A, B, C, D, E, F with weighted edges A–B (5), A–C (6), A–D (4), A–F (3), B–D (8), B–E (5), B–F (6), C–F (6)…
- Array A = [27, 21, 20, 5, 13, 9, 28] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?
- Coins of denominations [11, 10, 7, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 20?…