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?

  1. A. 3
  2. B. 6
  3. C. 4
  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.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic