LeetCode 127. Word Ladder [Algorithm + Code Explained ] Best Solution

preview_player
Показать описание
One of the most frequently asked coding interview questions on Arrays in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe etc.

LeetCode : Word Ladder

Question : Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such that:

Only one letter can be changed at a time.
Each transformed word must exist in the word list. Note that beginWord is not a transformed word.
Note:

Return 0 if there is no such transformation sequence.
All words have the same length.
All words contain only lowercase alphabetic characters.
You may assume no duplicates in the word list.
You may assume beginWord and endWord are non-empty and are not the same.

Example 1:

Input:
beginWord = "hit",
endWord = "cog",

wordList = ["hot","dot","dog","lot","log","cog"]

Output: 5

Рекомендации по теме
Комментарии
Автор

Perfect explanation, Thank you.
Expecting more questions and approaches.

prayagbhatt
Автор

I loved your solution so much! Do you plan on adding a solution for Ladder 2? Please do so. I would love to see what brilliant solution you come up with!

joseba
Автор

Hi, I tried your solution in c#. It gives me the length as 6 with following transformation :
"hit" -> "hot" -> "dot" -> "dog" ->"log"-> "cog"

The reason is that after removing "dog" from the iterator, it has "log" before "cog" .

akshayg
Автор

Didn't you miss the O(n) everytime you remove the item from List, though it will not have any major impact.

MrArpit
Автор

Thanks a lot for your great explanaion. Please keep posting more video on leetcode problems as well as system design.

ChandraShekhar-bycd
Автор

Hi,
I am solving Leetcode.Will solving top 150 frequently asked questions enough to crack product based?I

sohamdutta
Автор

Ma'am please make video on word ladder II as well 126 leetcode

pallavijadhav
Автор

This solution Gave TLE when used with C++

ananysharma
Автор

And plz tell me from where i can learm

shivaay
Автор

i think you missed scenario of multiple paths. Case where you have different possible paths.

georgerahul
Автор

Great Explanation!!
ListIterator's remove() complexity is O(n), alternatively we can construct a Hashset for an amortized O(1) remove() although without any effect on overall time complexity.

rajatgoyal
Автор

I felt that she kept working code aside and then referring the code and typing it and just reading out loud what she is typing. Didnt understood at all what she is trying to explain sorry.

bhavikshah
Автор

Yaar yhe tho galat hai na mai tho poora time ishi ko hi dekhta raha logic tho samjha hi nahi 🥰🥰🥰😍😍😍😍

thefuntech
Автор

Change this video title to "Worst explanation!!!, Don't waste your time."

priyatamroy
join shbcf.ru