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.)
- A. 4
- B. 6
- C. 5
- 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.
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
- In this grid, how many islands of 1s are there with 4-directional connectivity, and how many with 8-directional (diagonals also connect)?…
- What is the maximum path sum in this binary tree, where a path joins any two nodes along parent–child links and need not pass through the…
- A binary trie over 4-bit numbers finds the maximum XOR of any pair from [3, 10, 5, 9, 2, 8]. What is the maximum XOR?
- In a binary tree whose root is at level 0, what is the maximum number of nodes at level 5?
- A simple directed graph (no self-loops, at most one edge from u to v) has 6 vertices. What is the maximum number of edges?
- Which algorithm finds shortest paths (by number of edges) from one source in an UNWEIGHTED graph in O(V + E) time?