Determine the Edit Distance in a Word Ladder
Updated
Problem statement
Given two words (beginWord and endWord), and a dictionary's word list, find the minimum number of operations needed to change beginWord into endWord.
You can change only one letter at a time, and each intermediate word must exist in the word list. If there is no possible transformation, return None (Python), -1 (Java & C++), null (Javascript).
Function
ladderLength(beginWord: String, endWord: String, wordList: List<String>) → intExamples
Example 1
beginWord = "hit"endWord = "cog"wordList = ["hit", "hot", "dot", "dog", "cog"]return = 4
The transformation sequence can be: hit -> hot -> dot -> dog -> cog, which is 4 steps long.
Example 2
beginWord = "word"endWord = "word"wordList = ["word", "ward"]return = 0
Since the beginWord is the same as the endWord, no transformation is needed, so the number of steps is 0.
Example 3
beginWord = "hit"endWord = "cog"wordList = ["hit", "hot", "dot", "dog"]return = -1
The word cog is not in the list, so there is no possible transformation sequence.
More Adobe interview questions
- Base Unit ConversionsOA · Seen Nov 2026
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Top-Funded Villages and ProjectsOA · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Lowest Common Ancestor Only When Both Targets ExistONSITE INTERVIEW · Seen Aug 2026
- Lowest Common Ancestor with Parent PointersONSITE INTERVIEW · Seen Aug 2026
- Next and Previous Lexicographic PermutationONSITE INTERVIEW · Seen Aug 2026
- Asteroid CollisionONSITE INTERVIEW · Seen Aug 2026
Similar questions at other companies
- Detonate the Maximum BombsZomato / Eternal · PHONE SCREENZomato / Eternal interview questions
- Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
- Shortest Word Chain Between Two WordsFanatics · PHONE SCREEN
- Course ScheduleByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Merge Accounts by Shared AttributeAmazon · PHONE SCREEN
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Shortest Pin Path Through TopicsPinterest · PHONE SCREENPinterest interview questions
- Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
- Word Chain Jumps in a GridGoogle · PHONE SCREENGoogle interview questions
- Delivery Management SystemAkuna Capital · OAAkuna Capital interview questions