Word Ladder 2 | Leetcode

  Рет қаралды 47,018

Techdose

Techdose

Күн бұрын

Пікірлер: 92
@RahulVerma-fz2jf
@RahulVerma-fz2jf 3 жыл бұрын
Really good. After going to 10 editorials, I finally understood Word Ladder 2 using this video. I am sure, I won't be forgetting it next time. Keep up the good work. :)
@techdose4u
@techdose4u 3 жыл бұрын
Nice :)
@JCatharsis
@JCatharsis 3 жыл бұрын
Your approach seems the most intuitive and easy to understand compared to all leetcode solutions.. cheers mate
@shivambharti8278
@shivambharti8278 2 жыл бұрын
Giving TLE as of now. 32/35 test case passed :)
@tanmoypaul4268
@tanmoypaul4268 2 жыл бұрын
Have u figured out why its giving tle?
@shivanshrawat2688
@shivanshrawat2688 4 жыл бұрын
I was just going to post a comment to ask you to put out a video for this problem. there is simply no good explanation for this one, and I was constantly checking your page if you have uploaded solution to word ladder 2 because i knew that i would only understand it over here. Many thanks and more thanks. This page is absolutely brilliant.
@techdose4u
@techdose4u 4 жыл бұрын
Welcome bro :)
@babulbhanu8213
@babulbhanu8213 3 жыл бұрын
Teaching is an art and you have mastered it . Thank you so much :)
@techdose4u
@techdose4u 3 жыл бұрын
Welcome :)
@sthirumalai
@sthirumalai 4 жыл бұрын
Hi, Your thought process is crystal clear. I implemented the solution using two BFS iterations instead of a BFS+DFS. But the intuition is the same. Great content. Thanks
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@learn5371
@learn5371 2 жыл бұрын
People like you make India proud
@avinandanbanerjee9568
@avinandanbanerjee9568 4 жыл бұрын
Thanks for the clear explanation! I wasn't able to get the special adjacency list, and leetcode solutions were very cryptic.
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@aushoroup2992
@aushoroup2992 3 жыл бұрын
"Special Adjacency List" is the key. I got TLE while using the Normal Adjacency list. Thanks for helping me out.
@srishtijaiswal7079
@srishtijaiswal7079 2 жыл бұрын
No tle if you use a visited hashmap parallel
@madmax2442
@madmax2442 3 жыл бұрын
This was a tough one and still you made so clear! Hats off 🎩
@andreafabris893
@andreafabris893 3 жыл бұрын
Could you explain why the time Complexity of DFS is V*E in this case and not V+E? Thank you
@1tav0
@1tav0 2 жыл бұрын
Thank you so much for this explanantion this problem is not easy at all and ive learned it with this video. thank you so much
@MrJoyRana
@MrJoyRana 6 ай бұрын
Great man!! I really struggled to understand and found this one, I was assured it's techdose :)
@yitingg7942
@yitingg7942 3 жыл бұрын
lol at the first second when I saw the graph you drew, I knew how to solve it. Thank you for being so inspiring Sir!
@techdose4u
@techdose4u 3 жыл бұрын
😂 shit. You dint watch the video 🤣
@yitingg7942
@yitingg7942 3 жыл бұрын
@@techdose4u hahahaha you caught me Sir! I actually still did Sir. I am half way now, trying to write the code while watching the video.
@techdose4u
@techdose4u 3 жыл бұрын
Nice 😊 All the best 👍🏼
@yitingg7942
@yitingg7942 3 жыл бұрын
@@techdose4u Sir I was so naive, I thought I knew the answer so I skipped the second part. Then it took me hours struggling without getting the code right. Today I came back and saw the second part, only to find that I am a complete idiot by skipping it. Since you made everything crystal clear. If I have followed your process, I wouldn't struggle for that long. Thank you so much Sir. I appreciate everyday that you are here!!!!!!!
@techdose4u
@techdose4u 3 жыл бұрын
Atleast you tried on your own. I am pleased to see that ❣️
@vishalmishra9549
@vishalmishra9549 3 жыл бұрын
Thank you for this great solution. Learned new thing.
@techdose4u
@techdose4u 3 жыл бұрын
Great :)
@lisaren6661
@lisaren6661 2 жыл бұрын
Wow! This is super clear. Thanks you so much!
@techdose4u
@techdose4u 2 жыл бұрын
Welcome 😄
@rosail21
@rosail21 4 жыл бұрын
Excellent Solution....Love your detailed analysis....Very unique an Enjoyable!
@techdose4u
@techdose4u 4 жыл бұрын
Thanks
@_inspireverse___
@_inspireverse___ 2 жыл бұрын
Awesome! You made it so easy and clear ❤❤
@nikhilpawariaaa
@nikhilpawariaaa 2 жыл бұрын
THIS HELPED ME A LOT! THANKS
@Donutshop2365
@Donutshop2365 3 жыл бұрын
Really good intuitive approach, but would TLE.
@techdose4u
@techdose4u 3 жыл бұрын
:O
@uditagrawal6603
@uditagrawal6603 3 жыл бұрын
@@techdose4u Initially was getting TLE but after optimisation with adjacency list it worked out. Nice approach!!!
@harshitpandey7521
@harshitpandey7521 3 жыл бұрын
Why is the complexity of DFS traversal O(VE), shouldn't it be O(V+E)?
@tanujgupta143
@tanujgupta143 3 жыл бұрын
it is not a simple DFS call. Simple traversing nodes using DFS gives O(V+E). This DFS prints all possible paths. Hence its worst time can be O(VE), best case can be O(V+E)
@dhanashreegodase4445
@dhanashreegodase4445 2 жыл бұрын
gonna sleep for straight 2 hours after this question
@techdose4u
@techdose4u 2 жыл бұрын
😄
@satyanarayanagokavarapu3011
@satyanarayanagokavarapu3011 4 жыл бұрын
Can you explain Guess the word problem ? That would be helpful
@dataman4503
@dataman4503 3 жыл бұрын
This problem is a bit hard. To solve this problem we need to use many DS (maps, queues, vectors,... ) . Lol.. I think if such questions are asked in Inteviews there is possibility that 1 hour will be consumed by this 1 problem alone.
@KM_1947
@KM_1947 3 жыл бұрын
Really good explanation. Can you clarify why BFS alone would not suffice. While calculating minimum depth itself can't we maintain the path from startWord to the current node as an attribute of that node and return that attribuite when we reach endWord.
@abhishekbarman1837
@abhishekbarman1837 4 жыл бұрын
I tried the code but instead of "dict.count" i used "dict.find" it gave TLE can u explain why ? and same for visited
@code_life4835
@code_life4835 4 жыл бұрын
Great Explanation Sir! Congrats for 30K Subscribers!
@techdose4u
@techdose4u 4 жыл бұрын
Thanks :)
@tapeshmittal3287
@tapeshmittal3287 3 жыл бұрын
Super video! I applauded for $2.00 👏
@techdose4u
@techdose4u 3 жыл бұрын
Thanks for your support ❤️
@Phoenix-xi2gy
@Phoenix-xi2gy 3 жыл бұрын
Can u pls explain how the time Complexity of DFS will be V*E in this case? BTW love your videos.. Keep doing the good work!
@PraddyumnShukla
@PraddyumnShukla 2 жыл бұрын
This solution gives TLE
@vinayakgandhi5690
@vinayakgandhi5690 2 жыл бұрын
Instead of using the special adjacency list, can we just create a normal adjacency list like an undirected graph and keep a dfs visited array to make sure we don't visit any node again in one dfs path, but can visit it in some other dfs path?
@chris.w391
@chris.w391 3 жыл бұрын
18:16 DFS in adjacency list should take O(V+E), right?
@rahulchudasama9363
@rahulchudasama9363 4 жыл бұрын
Through this video, I realized what u think u can do it in code. Many times I feel whatever I am thinking as a solution is lengthy and it will be hard to debug and what if it will not work with hidden/many test cases? Thanks, TechDose :)
@techdose4u
@techdose4u 4 жыл бұрын
Welcome :)
@sushantkumar9711
@sushantkumar9711 2 жыл бұрын
I think if we are facing difficulty understanding the special adjacency matrix. we can create a normal adjacency matrix and check if the current level is equal to the min level which we get from the BFS part and the current string is equal to the end word. if this is the case add else not. any views on this?
@secondIncomePartTime
@secondIncomePartTime 2 жыл бұрын
bhad faad diya bhai
@PriyanshuKumar-ho7kj
@PriyanshuKumar-ho7kj 2 жыл бұрын
Gives TLE now...although good approach
@LeoLeo-nx5gi
@LeoLeo-nx5gi 4 жыл бұрын
Sir pls if u start DP pls do good hard level problems bcoz whether any one says or not one can find the easy level and most famous dp problems everywhere so that would really be waste of time to go on with the usual ones like LCS and so on.... I hope u understand Sir, sorry if I said something wrong but I wanted to say it before u were about to start🙏
@techdose4u
@techdose4u 4 жыл бұрын
I will do problems of different types. All questions can't be very hard else very few will understand. I will do mix of problems.
@RajeshKumar-ts4fw
@RajeshKumar-ts4fw 2 жыл бұрын
this solution gives tle now
@gomzysharma
@gomzysharma 2 жыл бұрын
Getting TLE with this code+approach. Anyone else?
@MrNeo086
@MrNeo086 3 жыл бұрын
Amazing!
@techdose4u
@techdose4u 3 жыл бұрын
Thanks :)
@LegitGamer2345
@LegitGamer2345 3 жыл бұрын
java version : class Solution { public List findLadders(String beginWord, String endWord, List wordList) { HashMap adj = new HashMap(); HashSet dict = new HashSet(wordList); Queue Q = new ArrayDeque(); Q.add(beginWord); HashMap visited = new HashMap(); visited.put(beginWord,0); while(Q.size()>0){ String curr = Q.remove(); for(int i =0;i
@techdose4u
@techdose4u 3 жыл бұрын
👍🏼
@munendragaur4965
@munendragaur4965 Жыл бұрын
@@techdose4u solution is giving tle
@nikhilmehta7298
@nikhilmehta7298 2 жыл бұрын
It will return empty matrix after executing same code please help me in that
@shoaibakhtarshaikh3840
@shoaibakhtarshaikh3840 4 жыл бұрын
sir we should be able to traverse from both the sides ?what if we want to transform word log to hit in this case we will not be able to find the path
@benjaminross5615
@benjaminross5615 4 жыл бұрын
The structure of the DAG that is generated using this modified bfs algorithm is dependent on the start word and stop word. If the start word is “log” and the stop word is “hit” the graph would look different.
@amitupadhyay6511
@amitupadhyay6511 2 жыл бұрын
It gives TLE in python
@danlan4132
@danlan4132 2 жыл бұрын
same for c++ as well
@sauravawesome
@sauravawesome 3 жыл бұрын
if I use vis[temp] == 0 instead of vis.count(temp)==0 ,it gives runtime error can't see how or why ,can you please make this clear
@madmax2442
@madmax2442 3 жыл бұрын
Because vis[temp] = 0 means that you have you have visited 'temp' and its level is zero (and in actuality, temp is still unvisited) and so you will not include it in your path. We have to include the ones who are not visited.. So, either use "vis.count(temp) == 0" or "vis.find(temp) == vis.end()" to apply the correct logic.
@shiqilyu6692
@shiqilyu6692 2 жыл бұрын
same problem.
@anujtyagi4047
@anujtyagi4047 2 жыл бұрын
your code giving tle
@UTTAMKUMAR-wd4zz
@UTTAMKUMAR-wd4zz 2 жыл бұрын
TLE aara bae.
@rupalimaheshwari3024
@rupalimaheshwari3024 2 жыл бұрын
26^N?
@yogeshsikanderpuriya7417
@yogeshsikanderpuriya7417 2 жыл бұрын
getting tle now
@juzarantri864
@juzarantri864 2 жыл бұрын
did u solved bro??
@player-te8tf
@player-te8tf 2 жыл бұрын
@@juzarantri864 Yea
@juzarantri864
@juzarantri864 2 жыл бұрын
@@player-te8tf please tell me from where did u find the approach and how u did it?
@player-te8tf
@player-te8tf 2 жыл бұрын
@@juzarantri864 man i mean i solved it with the approch explained in the video, but it gave TLE. and this s*it requires higher brain functionality which i lack now... So i have added it in my to do list and will look into this q after i complete graph
@player-te8tf
@player-te8tf 2 жыл бұрын
And yea... If u really wanna solve it then go to the leetcode discussion >
@ghazanferwahab5673
@ghazanferwahab5673 3 жыл бұрын
plz give coe in java
@CareerHunt
@CareerHunt 2 жыл бұрын
//100% pass test cases class Solution { public: void findAllPath(vector &res, string currentWord, string beginWord, unordered_map &parents, vector path) { if(currentWord == beginWord) { path.push_back(beginWord); reverse(path.begin(), path.end()); res.push_back(path); return; } for(auto word: parents[currentWord]) { path.push_back(currentWord); findAllPath(res, word, beginWord, parents, path); path.pop_back(); } } vector findLadders(string beginWord, string endWord, vector& wordList) { unordered_map wordMap; unordered_map parents; unordered_map levels; for(auto word: wordList) { wordMap[word] = true; } queue q; q.push(beginWord); int level = 0; levels[beginWord] = 0; while(!q.empty()) { string s = q.front(); q.pop(); for(int i=0; i
@tausifnawaz8187
@tausifnawaz8187 2 жыл бұрын
can you please explain the problem in the original code and what changes you made to make the code work, I'm struggling to come to a conclusion???
@CareerHunt
@CareerHunt 2 жыл бұрын
@@tausifnawaz8187 from this method, we are coming from end to starting while calculating path
@CareerHunt
@CareerHunt 2 жыл бұрын
@@tausifnawaz8187 in the above video code, time limit happening due to multiple DFS on neighbours while calculating path. Suppose our level is more than 1+ level of curr. Then, We were not doing anything with those neighbours. But it should not be like that. So, in this approach we are trying to remove those neighbours whose level diff is more than one.
@nanotasza
@nanotasza 7 ай бұрын
@@CareerHuntThis is genius, thanks!
Word Ladder | Leetcode #127
19:19
Techdose
Рет қаралды 72 М.
Long Nails 💅🏻 #shorts
00:50
Mr DegrEE
Рет қаралды 14 МЛН
When u fight over the armrest
00:41
Adam W
Рет қаралды 31 МЛН
Disrespect or Respect 💔❤️
00:27
Thiago Productions
Рет қаралды 43 МЛН
G-30. Word Ladder - 2 | Shortest Paths
25:42
take U forward
Рет қаралды 141 М.
Word Ladder - Breadth First Search - Leetcode 127 - Python
17:06
LeetCode 126. Word Ladder II
14:48
Happy Coding
Рет қаралды 6 М.
The LeetCode Fallacy
6:08
NeetCode
Рет қаралды 575 М.
WORD LADDER | LEETCODE # 127 | PYTHON BFS SOLUTION
23:17
Cracking FAANG
Рет қаралды 1,8 М.
Find Median from Data Stream
29:28
Techdose
Рет қаралды 55 М.
G-31. Word Ladder - 2 | Optimised Approach for Leetcode
23:40
take U forward
Рет қаралды 80 М.
Network Delay Time | Leetcode #743
19:37
Techdose
Рет қаралды 19 М.
Word Search II | DFS + Map | DFS + TRIE | Leetcode #212
24:49
Word Ladder | Breadth First Search (LeetCode)
15:08
AlgosWithMichael
Рет қаралды 14 М.
Long Nails 💅🏻 #shorts
00:50
Mr DegrEE
Рет қаралды 14 МЛН