Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Shortest Transformation Sequence Length

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Shortest Transformation Sequence Length. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given a begin_word string, an end_word string, and a list of unique lowercase strings word_list, return the length of the shortest transformation sequence from begin_word to end_word. A valid transformation changes exactly one character at a time, and every intermediate word must exist in word_list. Return 0 if no such sequence exists.

Constraints

  • 1 <= len(begin_word) <= 10
  • len(begin_word) == len(end_word) == len(word_list[i])
  • 1 <= len(word_list) <= 5000
  • All strings contain only lowercase English letters
  • All words in word_list are unique

Function Signature

def ladder_length(begin_word, end_word, word_list):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output