Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Trending in AI
Hot
Agentic AI EngineerForward-Deployed EngineerGenAI EngineerAI Architect
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Start free
Find Shortest Word Ladder Sequence
00:00
5 left

Find Shortest Word Ladder Sequence

MediumPython

Problem

In a Duolingo vocabulary lesson, a learner can transform one word into another by changing exactly one character at a time. Every intermediate word must appear in the supplied vocabulary. Given a starting word, a target word, and the vocabulary, return the minimum number of words in a valid transformation sequence, including both endpoints. Return 0 if no sequence exists.

Formal Specification

Implement shortest_word_ladder(begin_word, end_word, word_list).

  • begin_word: a lowercase string.
  • end_word: a lowercase string with the same length as begin_word.
  • word_list: a list of lowercase vocabulary strings, all with the same length.
  • Return an integer representing the shortest sequence length, or 0 when the target cannot be reached.

Two words are adjacent when they have the same length and differ in exactly one position.

Constraints

  • 1 <= len(begin_word) = len(end_word) <= 10
  • 1 <= len(word_list) <= 5 * 10^4
  • All words contain lowercase English letters
  • Duplicate vocabulary entries may be ignored
  • Return 0 when end_word is unreachable or absent

Function Signature

def shortest_word_ladder(begin_word, end_word, word_list):
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements are in the Question tab.

Sign up free to run or submit. Log in
Code
Sign up free to run your code. Your draft is saved.Run with a free accountLog inLn 2
Run your code to see test output here.