Тёмный

Word Ladder | Breadth First Search (LeetCode) 

AlgosWithMichael
Подписаться 21 тыс.
Просмотров 14 тыс.
50% 1

Наука

Опубликовано:

 

23 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 75   
@babydriver7062
@babydriver7062 4 года назад
love the explanation on time-complexity. happy that you are one of among the very few who bothers to explain T(n)
@AlgosWithMichael
@AlgosWithMichael 4 года назад
Thank you! Complexity analysis is crucial for interviews
@damilolaodunbaku5126
@damilolaodunbaku5126 3 года назад
You are literally the best! You put so much effort into explaining the solutions and make them crystal clear and soooooo easy to understand. Well done
@AlgosWithMichael
@AlgosWithMichael 3 года назад
Thank you! Learning this stuff is hard and I want to try to help out as many people as possible
@quantum598
@quantum598 3 года назад
What an explanation...ONE OF the few who goes into this much depth about time complexity!! Thank you dude!!!!
@quantum598
@quantum598 3 года назад
i sadly got TLE :/
@AlgosWithMichael
@AlgosWithMichael 3 года назад
Thank you!
@AlgosWithMichael
@AlgosWithMichael 3 года назад
Make sure you have a check if the start and end are equal
@swati8539
@swati8539 3 года назад
Awesome explanation of code with clean example.
@StyleTrick
@StyleTrick 3 года назад
Really great explanation, you should become an instructor at AlgoExpert, you break things down incredibly well!
@AlgosWithMichael
@AlgosWithMichael 3 года назад
Thanks! 😃
@sase1017
@sase1017 4 года назад
You added twice of queue.add(beginWord)?
@AlgosWithMichael
@AlgosWithMichael 4 года назад
Yea, I fix it later on I think haha
@sase1017
@sase1017 4 года назад
very clear logics and coding steps, great job, learned quite a bit
@AlgosWithMichael
@AlgosWithMichael 4 года назад
Great to hear!
@ameynaik2743
@ameynaik2743 3 года назад
Great video, why can’t we just loop over given words and check the difference with current word poped from the queue ? Is there any advantage of looping over a-z and changing only one char at a time to create a new word?
@gnanyreddy3030
@gnanyreddy3030 2 года назад
Yeah, even I have solved the problem with the approach that you have mentioned
@globaltechmastery2393
@globaltechmastery2393 2 года назад
Great teaching
@code7434
@code7434 4 года назад
Thank u so much. Can you please tell which problem videos are upcoming?
@AlgosWithMichael
@AlgosWithMichael 4 года назад
Thank you for watching! I'm going to be posting a graph problem tips video in the upcoming week or two.
@rashmin3112
@rashmin3112 3 года назад
Why is there another loop for size of queue, what happens if I directly keep polling from the queue?
@sharan636
@sharan636 4 года назад
That was a great explanation! Thank you
@AlgosWithMichael
@AlgosWithMichael 4 года назад
Glad you enjoyed it!
@globaltechmastery2393
@globaltechmastery2393 2 года назад
Best so far
@testpark5647
@testpark5647 3 года назад
In line 10, why did you add the beginword twice to the queue? Were you suppose to add it inside the visited ?
@AlgosWithMichael
@AlgosWithMichael 3 года назад
Yea, it was a typo, I fix it later on in the video I think haha
@testpark5647
@testpark5647 3 года назад
@@AlgosWithMichael Thank you brother. Merry Christmas! I love your tutorial videos. Keep up to good work
@AlgosWithMichael
@AlgosWithMichael 3 года назад
Thank you! hope your holiday break was nice as well
@devgamer1543
@devgamer1543 3 года назад
Nice tutorial. Where can I insert the code to display the ladder word?
@shaziakaleem1895
@shaziakaleem1895 4 года назад
Very well explained. Thank you very much.
@AlgosWithMichael
@AlgosWithMichael 4 года назад
Glad it was helpful!
@ks-ow8mc
@ks-ow8mc 3 года назад
I think Line 21 would contribute O(M) too - where you convert the word to char array? But it wouldn't change the overall complexity.
@AlgosWithMichael
@AlgosWithMichael 3 года назад
Yep, agreed
@harshavardhanm7091
@harshavardhanm7091 2 года назад
Great explanation.. on line 10, do you mean visited.add(beginWord) because it was already added to the queue on line 7
@yitingg7942
@yitingg7942 3 года назад
Great great explanation Michael, can you also do one for 126? Similar to this however i can't solve it with the same approach.
@AlgosWithMichael
@AlgosWithMichael 3 года назад
I'll add to the list
@sase1017
@sase1017 3 года назад
revisiting this problem 2 weeks later, have no clue again, feeling like starting all over. it's crazy..
@AlgosWithMichael
@AlgosWithMichael 3 года назад
leetcode grind is rough
@mister_10k
@mister_10k 4 года назад
Hi Michael, I loved the tutorial. It helped me out a lot. Just struggling with the runtime a little. I understand the M^2 part, but for the first while loop & then the first for loop, how do those both amount to o(n) ?
@AlgosWithMichael
@AlgosWithMichael 4 года назад
You can think of N in this case as all words that end up getting added inside of our queue. Since our exit condition, in the worst case, is if we don't find a path and our queue is empty, we would have to dequeue all N words, hence the O(N). Hope that makes it bit more clear!
@mister_10k
@mister_10k 4 года назад
@@AlgosWithMichael so is the while(!queue.isEmpty) line relevant?
@AlgosWithMichael
@AlgosWithMichael 4 года назад
If there is no path from the start to end word, it would use that exit condition. Just depends on the input to the function
@mister_10k
@mister_10k 4 года назад
@@AlgosWithMichael Thanks Mike
@AlgosWithMichael
@AlgosWithMichael 4 года назад
Anytime!
@MegaSlim95
@MegaSlim95 3 года назад
Line 10 i think u meant visited.add(beginWord)???
@guruvigneshnagaraj8501
@guruvigneshnagaraj8501 4 года назад
Very succint explanation!! Thanks man!
@AlgosWithMichael
@AlgosWithMichael 4 года назад
My pleasure!
@sarvesh97
@sarvesh97 4 года назад
Beautifully explained! 🍻
@AlgosWithMichael
@AlgosWithMichael 4 года назад
Thank you!
@alammahtab08
@alammahtab08 4 года назад
Very well explained 👍👍👍
@AlgosWithMichael
@AlgosWithMichael 4 года назад
Thank you so much 🙂
@theghostwhowalk
@theghostwhowalk 4 года назад
Great Explanation! Cheers!
@AlgosWithMichael
@AlgosWithMichael 4 года назад
Glad it was helpful!
@rohitvishwakarma1238
@rohitvishwakarma1238 3 года назад
Hi Michael, a great explanation for this hard problem. I really appreciate it. I have some confusion understanding the space complexity O(M*N). I believe it should be O(M^2 * N).
@uditagrawal6603
@uditagrawal6603 3 года назад
There are some test cases not passing with this code. Example : "hot" "dog" ["hot","dog"] expected : 0 returned : 1 Modified code to make this work: class Solution { public int ladderLength(String beginWord, String endWord, List wordList) { Set wordSet = new HashSet(wordList); if(!wordSet.contains(endWord))return 0; Queue queue = new LinkedList(); queue.add(beginWord); Set visited = new HashSet(); visited.add(beginWord); int changes = 1; while(!queue.isEmpty()){ int size = queue.size(); for(int i = 0; i < size; i++){ String currentStr = queue.poll(); if(currentStr.equals(endWord))return changes; for(int j = 0; j < currentStr.length(); j++){ for(int k = 'a'; k
@ihsan_k
@ihsan_k 2 года назад
S, for new test cases.
@kennettemaddela5682
@kennettemaddela5682 2 года назад
I might be a year late, but the code shown in the video works for all test cases. The reason why you are returning 1 in that test case is because at your final line, you are returning changes and not 0. 0 is the correct value to be returned since we were not able to find a mutated word that equated to the end word.
@code7434
@code7434 4 года назад
Please add word ladder 2 as well
@AlgosWithMichael
@AlgosWithMichael 4 года назад
Yea, I like that problem as well
@riverintel1634
@riverintel1634 4 года назад
this was amazing!
@AlgosWithMichael
@AlgosWithMichael 4 года назад
Thank you!
@arjunsumanth1394
@arjunsumanth1394 4 года назад
Bro u creat object visited then y u add the word in queue ..line 10
@AlgosWithMichael
@AlgosWithMichael 4 года назад
Yea, I fix the mistake later on in the video
@navyaraga6504
@navyaraga6504 4 года назад
can u plz share the code in your github repo?
@AlgosWithMichael
@AlgosWithMichael 4 года назад
That is a good idea, I might start doing that
@sase1017
@sase1017 4 года назад
Can you also share the source code?
@AlgosWithMichael
@AlgosWithMichael 4 года назад
I can create a github repo, I'll post it when I create it
@sase1017
@sase1017 4 года назад
@@AlgosWithMichael Awesome, thank you, keep up the great work!
@mohammadaminelahimoghadam3312
@mohammadaminelahimoghadam3312 4 года назад
This is a freely available tutorial on the net and i am grateful for that (i have liked the vid already) however i need to remind you some points: Video title clearly says 'WORD LADDER' whatever your program does it does NOT solve for word ladders: This is a very specific question and you are required to return a list that shows: shortest path from start to end NOTHING LESS OR MORE and most importantly every transition in list must be valid (only one letter change at a time). so next time please try chose your title more carefully as your channel grows. Secondly, you didnt run your code at the end, did u?
@AlgosWithMichael
@AlgosWithMichael 4 года назад
I chose the title "Word Ladder" because that is the name of the problem on LeetCode. Many interview problems are not introduced as just "find shortest path from x to y", they are filled with large descriptions to throw off candidates haha. Also, I run the code at 12:36, it was a quick snippet. Thanks so much for watching, liking, and commenting!
@BeginnerMoto
@BeginnerMoto 4 года назад
Baeh
@AlgosWithMichael
@AlgosWithMichael 4 года назад
baeh
@ashutoshagrawal7871
@ashutoshagrawal7871 Год назад
in line 10 it should be visited.add(beginWord) ...right??
Далее
Google Coding Question - Divide Chocolate (LeetCode)
16:44
Word Ladder | Leetcode #127
19:19
Просмотров 71 тыс.
Paint Projects
00:17
Просмотров 4,9 млн
WORD LADDER | LEETCODE # 127 | PYTHON BFS SOLUTION
23:17
Coding Interview Tutorial 61: Word Ladder [LeetCode]
11:43
Breadth First Search | Word Ladder | LeetCode 127.
16:25
Leetcode - Word Ladder (Python)
13:30
Просмотров 3 тыс.
Coding Interview Prep | 3 MUST KNOW Graph Problem Tips
13:27
How I would learn Leetcode if I could start over
18:03
Просмотров 625 тыс.
Wireless switch part 177
0:58
Просмотров 18 млн
Секретные процессоры!
0:27
Просмотров 1 млн