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)?
- A. 3
- B. 6
- C. 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.
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
- Undirected graph on vertices A, B, C, D, E, F with edges, in this exact order: C–D (1), B–C (1), C–E (1), C–F (1), A–D (1), A–C (1)…
- A chain of 5 matrices M1 to M5 has dimensions given by the sequence p = [12, 16, 8, 10, 7, 10], where Mi has size p[i−1] × p[i]…
- A chain of 6 matrices M1 to M6 has dimensions given by the sequence p = [20, 8, 2, 10, 19, 2, 7], where Mi has size p[i−1] × p[i]…
- A trie keeps a counter at each node, and every word of the list W = ['a', 'c', 'a', 'a', 'cac', 'caa', 'bc', 'bcb'] is inserted once per…
- Tree with vertices 0 to 8, root 0, edges 0–1, 0–2, 1–3, 3–4, 2–5, 1–6, 1–7, 3–8 (parent–child). Vertex weights (vertex:weight) 0:10, 1:9…
- A chain of 4 matrices M1 to M4 has dimensions given by the sequence p = [17, 3, 2, 3, 5], where Mi has size p[i−1] × p[i] (1-indexed)…