Code Room
CodingMediumcod-g495
Subject BfsLevel Mid–Senior~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Given a begin word, an end word, and a dictionary of equal-length lowercase words, you may transform one word into another by changing exactly one letter at a time, and every intermediate word must be in the dictionary. Return the number of words in the shortest transformation sequence from begin to end, inclusive of both endpoints. The begin word need not be in the dictionary, but the end word must be. Return 0 if no transformation is possible. All words have length 1..10 and the dictionary has at most 5000 words.

Implement
ladder_length(begin: str, end: str, words: list[str]) → int
Examples
in["hit","cog",["hot","dot","dog","lot","log","cog"]]out5
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.