Data Structures & AlgorithmsVery hardProduct company OA

Word ladder: change one letter at a time, every intermediate word must be in the dictionary {cold, cord, card, ward, warm, word, worm, wore, core, wold}. What is the minimum number of WORDS in a sequence from cold to warm, both ends included? (BFS over words.)

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

Correct answer: C. 5

BFS levels: cold (1) → cord, wold (2) → card, word, core (3) → ward, worm, wore (4) → warm (5), e.g. cold → cord → word → worm → warm. Counting transformations (edges) instead of words gives 4.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic