Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2

Dictionary D = {bdc, bds, cat, gce, lpb, nig, pgm, rmm, seg, tgm, tgs, tms} (all words have 3 letters). Starting from the word 'pmm', a move changes exactly one letter, and every word you move to must be in D. What is the minimum number of words in a valid sequence from 'pmm' to 'tms' (counting both endpoints; 'pmm' itself need not be in D)?

  1. A. 3
  2. B. 6
  3. C. 4
  4. D. 5

Correct answer: D. 5

BFS over one-letter moves inside D gives 4 moves, so 5 words including both endpoints. Forgetting to count the start word gives one less, and Hamming distance ignores the dictionary.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic