Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2
Words ['ca', 'aa', 'dc', 'ab', 'dad', 'aca', 'aac'] (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. 7
- B. 4
- C. 6
- D. 3
Correct answer: C. 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
- Directed graph on vertices A, B, C, D, E, F, G with edges C→A, E→A, E→G, G→C, G→F, F→C, C→G, C→B (no weights). What is the number of…
- On an 8 × 8 chessboard with rows and columns numbered 0 to 7, a knight starts at (4, 7) and must reach (1, 0) (as (row, column)). A knight…
- A trie keeps a counter at each node, and every word of the list W = ['bbaa', 'bc', 'a', 'cbaa', 'ccac', 'a'] is inserted once per…
- A binary trie of 6-bit numbers stores the set S = [25, 51, 62, 29]. For the query x = 53, what is the maximum value of x XOR s over all s…
- Directed graph on vertices A, B, C, D, E, F, G with edges C→F, F→G, F→E, A→D, E→C, C→G, B→F, A→G, B→C, G→C, A→E. How many strongly…
- On an 7 × 7 chessboard with rows and columns numbered 0 to 6, a knight starts at (0, 0) and must reach (5, 1) (as (row, column)). A knight…