Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

beginWord =
endWord =
wordList =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Shortest transformation sequence in an unweighted graph => BFS.

Approach

Treat each word as a node; edge exists if words differ by 1 letter. BFS from beginWord, generating neighbors by changing each character a..z and checking membership in a set.

Why it works

BFS finds the shortest number of edges to reach endWord.

Code
Loading...
Complexity
Time: O(N * L * 26) worst-case
Space: O(N)
Solution
Updated: 2026-02-23

Idea

Shortest transformation sequence in an unweighted graph => BFS.

Approach

Treat each word as a node; edge exists if words differ by 1 letter. BFS from beginWord, generating neighbors by changing each character a..z and checking membership in a set.

Why it works

BFS finds the shortest number of edges to reach endWord.

Code
Loading...
Complexity
Time: O(N * L * 26) worst-case
Space: O(N)