Data Structures & AlgorithmsHardCodeforces Div 2 · ICPC regional
Dictionary D = {ada, ats, emd, lsc, pcd, pmd, pmo, pno, pnr, rbs, sbp, ssr} (all words have 3 letters). Starting from the word 'ptd', 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 'ptd' to 'pnr' (counting both endpoints; 'ptd' itself need not be in D)?
- A. 3
- B. 5
- C. 7
- D. 4
Correct answer: B. 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
- Complete undirected graph on vertices A to F with symmetric edge weights given row by row (row i, column j = weight of edge between…
- Array A = [29, 1, 24, 26, 13, 6, 8] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?
- Directed weighted graph on vertices A, B, C, D, E, F with edges listed in this exact order: A→D (7); C→E (0); D→B (2); F→A (2); C→D (5)…
- Keys are inserted in the order 56 88 11 17 79 25 68 into an empty binary search tree. Then the key 56 (which has two children) is deleted…
- Array A = [3, 1, 2, 3, 4, 1, 4, 1, 4]. An increasing subsequence is chosen by INDEX positions i1 < i2 < … with A[i1] < A[i2] < … (strictly…
- Connected undirected graph on vertices A, B, C, D, E, F, G, H with edges A–D (1), B–F (1), B–H (1), C–D (1), D–E (1), D–H (1), E–G (1)…