Z34
Word Ladder Shortest Transformation
Problem Statement & Objective
A transformation sequence from word beginWord to word endWord using a dictionary wordList. Return the number of words in the shortest transformation sequence.
Function Signature (Python)
word_ladder_shortest_transformation(start: str, target: str, words: list[str]) -> intInput & Output Contract
Output Rule:En kısa dönüşüm zincirindeki kelime sayısı. Yoksa 0.
System Constraints
1 <= baslangic.length <= 10
hedef.length == baslangic.length
1 <= kelimeler.length <= 5000
Tüm kelimeler küçük harf içerir ve aynı uzunluktadırExample Execution Walkthrough
baslangic = 'hit', hedef = 'cog', kelimeler = ['hot','dot','dog','lot','log','cog']
'hit' -> 'hot' -> 'dot' -> 'dog' -> 'cog' (5 kelime)
cevap: 5Example Test Scenarios (3)
Example 1
Input:
["hit","cog",["hot","dot","dog","lot","log","cog"]]Expected Output:
5Example 2: Hedef Sözlükte Yok
Input:
["hit","cog",["hot","dot","dog","lot","log"]]Expected Output:
0Example 3: Tek Harfli
Input:
["a","c",["a","b","c"]]Expected Output:
2