Тёмный

Coding Interview Tutorial 61: Word Ladder [LeetCode] 

Amell Peralta
Подписаться 18 тыс.
Просмотров 14 тыс.
50% 1

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

 

23 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 50   
@johnde392
@johnde392 5 лет назад
Please amell,Complete all the Problems in LeetCode,Dont stop your Videos and efforts.Your are Awesome.God bless you.
@amellperalta
@amellperalta 5 лет назад
Thank you, John. God bless you, too.
@ankit_irl
@ankit_irl 3 года назад
Man great video! This is quality content. Thank you
@amellperalta
@amellperalta 3 года назад
You're quite welcome!
@byunjins
@byunjins 5 лет назад
Great explanation :) I didn't realize that I could make a for loop using char (line 16). Thanks!
@amellperalta
@amellperalta 5 лет назад
Thank you, Jin. Happy coding!
@Niyatpatel23295
@Niyatpatel23295 5 лет назад
No need to check !s.equals(word) on line 19, Because We are removing this word from wordSet anyway so the possibility of duplicate is anyway handled.
@nickscriv5141
@nickscriv5141 4 года назад
no, you need that check on line 19 you imbecile.
@Nothanksmrray
@Nothanksmrray 3 года назад
@@nickscriv5141 why? There is no way there will be a duplicate since this is a hashset.
@siddharthsharma3679
@siddharthsharma3679 4 года назад
Good Stuff Amell, Of all the coders who teach leetcode on RU-vid - you're my favorite =) Thanks a lot man (F)
@amellperalta
@amellperalta 4 года назад
You're welcome, Siddharth!
@srikantsharma6430
@srikantsharma6430 4 года назад
Nice explanation!
@amellperalta
@amellperalta 4 года назад
Thank you. Happy coding!
@parvezmulla3324
@parvezmulla3324 4 года назад
amazing explaination dude! Thanks for it.
@amellperalta
@amellperalta 4 года назад
You're welcome!
@avinashmv9686894578
@avinashmv9686894578 5 лет назад
Took a while to understand, but an awesome explanation. Thanks.
@amellperalta
@amellperalta 5 лет назад
You're welcome, Avinash. Happy coding!
@avinashmv9686894578
@avinashmv9686894578 5 лет назад
Hey Amell, when I played around, I found that if I change the way the queue is processed, for(int k=q.size();k>0 ;k--) to for(int k=0;k
@anurag_arora
@anurag_arora 5 лет назад
@@avinashmv9686894578 Take q.size() out of the loop. The reason it is not working for you is because the size of the queue keeps on changing.
@pushkarraj3839
@pushkarraj3839 5 лет назад
@@anurag_arora guys have you done 126. Word Ladder II
@tapasu7514
@tapasu7514 5 лет назад
Best Explanation ever!
@amellperalta
@amellperalta 5 лет назад
Thank you, Tapas. Happy coding!
@karthikvadla4370
@karthikvadla4370 5 лет назад
Great video, Thanks for the explanation :)
@amellperalta
@amellperalta 5 лет назад
Thank you, Karthik. Happy coding!
@jackieh2195
@jackieh2195 5 лет назад
Good video! but why the time complexity is (the average length of the words * the number of words)? Doesn line 16 costs time too?
@sonicdrivein736
@sonicdrivein736 5 лет назад
I believe because that's O(26) which is constant time, it's a non-dominant term and can be ignored as it won't have any effect on the run-time as the problem input grows.
@pushkarraj3839
@pushkarraj3839 5 лет назад
can you explain the 126. Word Ladder II
@amellperalta
@amellperalta 5 лет назад
Yes, Pushkar. I'll do that problem soon.
@ashutoshse1
@ashutoshse1 4 года назад
I am gwetting TLE in this.. any reason why?
@ianchui
@ianchui 5 лет назад
jesus, i've been looking at this problem for like two hours now
@amellperalta
@amellperalta 5 лет назад
Keep up the focus, Ian. It's worth the effort. Happy coding!
@amitranjan6998
@amitranjan6998 5 лет назад
@Amell "lost" "cost" ["most","fist","lost","cost","fish"] why it's output is 2 ?? , second y outer for loop is in reverse order.
@zhuolunzhou6074
@zhuolunzhou6074 5 лет назад
There's a bug in this code. We need to store size of q ahead, then use that in the for loop because q's size is changing inside the loop.
@wigcrafter
@wigcrafter 4 года назад
@@zhuolunzhou6074 I felt werid when he typed queue.size() and was wondering the size would change along with we offer the new word, thanks for pointing out!
@jimmycheng709
@jimmycheng709 3 года назад
@@wigcrafter This is not a bug. Because the k is initialized with the q.size(), after that k is used for the loop.
@SaumyaBhatnagar1
@SaumyaBhatnagar1 4 года назад
O(n*L^2) is the time complexity
@CODINC
@CODINC 5 лет назад
Is it O(n^3) solution?
@amellperalta
@amellperalta 5 лет назад
The time complexity is O(L * N), where L is the length of each word and N is the number of words.
@Nobody2310
@Nobody2310 5 лет назад
Thanks! Can you please do word ladder II?
@amellperalta
@amellperalta 5 лет назад
You're welcome! Yes, I'll do that problem soon. Thanks.
@jimmycheng709
@jimmycheng709 3 года назад
@@amellperalta Hi Amell, looking forward to your word ladder II. Thank you very much!
@suhasnayak4704
@suhasnayak4704 5 лет назад
Great video, thanks! But can you please explain why did you decide to go with BFS instead of DFS ? Can this be solved using DFS ? Also, can you please explain the time and space complexity in bit more detail.
@amellperalta
@amellperalta 5 лет назад
Thank you, Nayak. In this problem, it's necessary to use BFS because it finds the length of the shortest path. DFS will not work for this problem because it will not necessarily find the length of the shortest path. The time complexity is O(L * N), where L is the length of each word and N is the number of words.
@jacobotapia8617
@jacobotapia8617 5 лет назад
What does the for with k is used? It does nothing
@shweta1013
@shweta1013 5 лет назад
Same question. There is only one element in queue at any time, why do we need a loop. Not sure if my understanding is correct
@jayeshpokharkar2708
@jayeshpokharkar2708 4 года назад
Why do we need wordSet.remove(s);
@siddharthsharma3679
@siddharthsharma3679 4 года назад
so you dont repeat the same word again. for ex: when you transform from DOG -> COG, you don't want to go from COG -> DOG again. I can expand on that if you want. =)
@KM-star
@KM-star 5 лет назад
"lost" "cost" ["most","fist","lost","cost","fish"] Why does this test case expect output as 2 in leetcode? It should be 1 m assuming. Also, the code in the video gives 1 for this TC.
@amitranjan6998
@amitranjan6998 5 лет назад
@K M when you reverse outer for loop you get expected output as 2 , but when i start i=0 in for loop then i get 1 , i also can't undeerstand y it's showing 2
Далее
Coding Interview Tutorial 146 - Sort List [LeetCode]
10:55
ТЕСЛА КИБЕРТРАК x WYLSACOM / РАЗГОН
1:40:47
Google Coding Interview Question - firstDuplicate
20:17
Decode Ways
7:31
Просмотров 105 тыс.
Walls and Gates
8:09
Просмотров 40 тыс.
LeetCode 290. Word Pattern Solution Explained - Java
8:58
Coding Interview Tutorial 153 - LRU Cache [LeetCode]
13:21
Breadth First Search | Word Ladder | LeetCode 127.
16:25
Unique Paths
7:07
Просмотров 60 тыс.