Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
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
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess 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
Build my plan
Word Ladder II Shortest Paths
00:00
5 left

Word Ladder II Shortest Paths

HardPython

Problem

Word Ladder II variation: find transformation sequences between two words (interviewer expected shortest paths).

Asked in the coding round 2 stage. BFS expected for shortest path.

Input and Output

Implement find_ladders(beginWord, endWord, wordList). Words have equal length. One transformation changes exactly one character, and every transformed word must be in wordList, except beginWord. Return all shortest sequences from beginWord to endWord, with each sequence represented as a list of words. Return [[beginWord]] when both words are equal and [] when no sequence exists.

Constraints

  • 1 <= len(beginWord) == len(endWord) <= 5
  • 1 <= len(wordList) <= 5000
  • All words contain lowercase English letters
  • wordList contains distinct words
  • All words in wordList have the same length as beginWord

Function Signature

def find_ladders(beginWord, endWord, wordList):
Interviewer

Your question is Word Ladder II Shortest Paths. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.