Sign In
You are coding as a Guest. Sign in with your RoleNest account to permanently track your streak, earn XP, and climb the Campus Leaderboard!
Sign In with RoleNest
🔥Word Ladder: BFS Shortest Transform SequenceHard
SUPER HARD PROBLEM OF THE DAY+150 XP • FAANG OA TIER

High-difficulty challenge matching authentic Google, Amazon & Uber L5 online assessment conditions.

HardTrees & Graphs•Acceptance: 39.1%

Word Ladder: BFS Shortest Transform Sequence

Targeted in FAANG & Tech OA:AmazonGoogleMicrosoft
Real-World Engineering Context
Powers shortest path state machine transitions, mutation evolutionary trees in bioinformatics, and game-solving graph search engines.
A transformation sequence from word `beginWord` to word `endWord` using a dictionary `wordList` is a sequence of words `beginWord -> s1 -> s2 -> ... -> sk` such that: - Every adjacent pair of words differs by exactly one letter. - Every `si` for `1 <= i <= k` is in `wordList` (`beginWord` does not need to be in `wordList`). - `sk == endWord`. Given two words, `beginWord` and `endWord`, and a dictionary `wordList`, return the number of words in the shortest transformation sequence, or `0` if no such sequence exists.

Sample Test Cases

Input: ["hit","cog",["hot","dot","dog","lot","log","cog"]]
Expected: 5
Input: ["hit","cog",["hot","dot","dog","lot","log"]]
Expected: 0
Input: ["a","c",["a","b","c"]]
Expected: 2

Constraints

  • 1 <= beginWord.length <= 10
  • endWord.length == beginWord.length
  • 1 <= wordList.length <= 5000
  • wordList[i].length == beginWord.length
  • beginWord, endWord, and wordList[i] consist of lowercase English letters.
  • beginWord != endWord
  • All words in wordList are unique.
Recruiter Fast-Track ReferralVerified Candidate
Direct pipeline to Google, Amazon, Microsoft, Swiggy, & Uber recruiters
DevScore: 750/1000

Top DevScore profiles bypass resume screening filters. Every verified problem solve writes authentic proof-of-work to your profile and dispatches you directly into employer inboxes on RoleNest.