G-31. Word Ladder - 2 | Optimised Approach for Leetcode

  Рет қаралды 87,628

take U forward

take U forward

Күн бұрын

Пікірлер: 162
@takeUforward
@takeUforward 2 жыл бұрын
Let's continue the habit of commenting “understood” if you got the entire video. Please give it a like too, you don't 😞 Do follow me on Instagram: striver_79
@chandannikhil8526
@chandannikhil8526 2 жыл бұрын
Bhaiya ek request hai "Evaluate division " wala ques bhi karana pls Ho nahi raha
@himanshu298
@himanshu298 2 жыл бұрын
Baaki log “Google” “Microsoft” ke name pe janta ka kaat te rahengey aur views lete rahengey. But ye banda apni mehnat consistency content quality se ek aisa level set kar jaega, jisse isko aane waali kai generations yaad rakhengi ♥️ Striver in real sense.
@codingwithanonymous890
@codingwithanonymous890 2 жыл бұрын
haan bhai true 2024 and 2025 batch ke liye toh gem hain yeh sab...paid course
@Anicienttimes
@Anicienttimes 2 жыл бұрын
agree
@artofwrick
@artofwrick 11 ай бұрын
Fantastic approach. I don't see any reason for interviewers to reject such a pretty backtracking algorithm
@mayurbhor2231
@mayurbhor2231 Жыл бұрын
I find this solution more intuitive than the previous one.
@sumedhakula7162
@sumedhakula7162 2 жыл бұрын
The smart DFS is such an IQ 200 move, Striver, thank you for sharing this with us!
@anvesh5377
@anvesh5377 2 жыл бұрын
Two months ago I submitted the python code for this problem and out of 7 submissions, one was accepted with barely 6000+ ms run time, and the others are TLE. But with this algorithm, it gave an average run time of 180ms for python. This much optimized algorithm. Thank you Striver.
@mohitsingh7793
@mohitsingh7793 Жыл бұрын
As he Said,it will be a cakewalk for a competetive programmer.Just got the goosebumps 😀
@muditkhanna8164
@muditkhanna8164 Жыл бұрын
this is not a cakewalk(in implementation) for us, probably for understanding its a cakewalk its like a 1600-1800 level question but it could go to 2000 if made some changes like find sequences only in lexicographical order
@Ahmed_Ataullah
@Ahmed_Ataullah 29 күн бұрын
Following you for the past few months and my problem solving ability has improved quite a lot. Thanks a lot.
@himadrinath1502
@himadrinath1502 13 күн бұрын
bhai mena cf pa 2000+ question kar liya Google nikal jai ga na??
@tanyacse6577
@tanyacse6577 2 жыл бұрын
That's reaally amazing man ❤‍🔥❤‍🔥❤‍🔥 THANK YOU for puting such amazing content , I just want to tell u that I follow your content DSA through out and I get internship in my dream company as a SDE Intern at Amazon. Thank you for putting such a amazing content for freee man really appericatiated 🙌🙌
@anishkarthik4309
@anishkarthik4309 2 жыл бұрын
could share your resume 📄? the one that got your intern at amazon.
@kaneframe5357
@kaneframe5357 6 ай бұрын
It might be even better to store vectors of words for each level in an array/vector eg- [0:[hit], 1:[hot], 2:[dot, lot], 3:[dog, log], 4:[cog]]. Then we can go back from cog checking for words on level 3 and seeing if difference in letters is 1. Such a method only compares the words up to 5 time (max no of letters in these words acc to leetcode) instead of 26. It is also faster due to access in array instead of a map. Pretty amazing solution, specially for conservation of memory. Thanks Striver :) Edit: Just realized another thing you can do is build an adj list at the start, which makes the process much simpler.
@niteshverma8281
@niteshverma8281 2 жыл бұрын
best youtuber for coding in the world ♥🧡🧡🧡🧡🧡🧡♥♥♥♥♥♥♥♥
@Dontpushyour_luck
@Dontpushyour_luck Жыл бұрын
First time I tried this problem, I did think of extending on the word ladder 1 concept by first calculating minimum seq length and then checking all sequences upto that length, probably that would have given me tle, this is a nice approach.
@subodhkasaudhaniitk796
@subodhkasaudhaniitk796 Жыл бұрын
Yes that gave TLE
@Health_asset
@Health_asset Жыл бұрын
I found this method best in between these two videos , first one was confusing , thanks striver sir
@shivankshukla2519
@shivankshukla2519 2 жыл бұрын
is this the end of this course. The way you make things easier is amazing. I THANK you for such helpful content creation, in every success of mine you are a great contributor.
@SaquibAnsariofficial01
@SaquibAnsariofficial01 Жыл бұрын
As a Competitive Programmer I find this solution the more concise and easiest though that dfs was really awesome
@imPriyansh77
@imPriyansh77 8 ай бұрын
Yeah
@parallax8916
@parallax8916 Жыл бұрын
Dude, I coded it myself after watching haldf of the vdeo and I found out the error u were talking about in 1 go!!! Thank u soo much bro for explaining soo tough problem in such a simple way!!!
@codinghustler6771
@codinghustler6771 2 жыл бұрын
Hey striver, first thank you for creating such great series for us. We love you so much. Because this is a graph series so we can discover a graph way of solving this problem. Convert the input into a unit weight undirected graph and then we will be able to find the solution using all paths using dfs solution. I have checked that by running on leetcode. Again thank you so much guruji.
@jayant-baid
@jayant-baid 2 жыл бұрын
Can you please send the solution
@artistyashwardhan8995
@artistyashwardhan8995 4 ай бұрын
after reading your comment i thought about this and came up solution, but this is giving TLE, it will be great help if you can share your solution. class Solution { unordered_map mpp; vector ans; string ew; private: void dfs(string word, unordered_map adj, vector& seq){ if(word == ew){ if(ans.size() == 0){ ans.push_back(seq); }else if(ans[0].size() >= seq.size()){ if(ans[0].size()>seq.size()){ ans.clear(); } ans.push_back(seq); } return; } for(auto it: adj[word]){ if(mpp[word] + 1
@TrendyGamer007
@TrendyGamer007 2 жыл бұрын
this is real content and that tooo for free..... striver can you make a compitative programming playlist from beginner level to advanced just like this one .... can't find any on youtube🙂
@sonit9707
@sonit9707 Жыл бұрын
The thing about cp is you will never find similar patterns of problems like you do on leetcode.
@lakshsinghania
@lakshsinghania Жыл бұрын
@@sonit9707 true
@lakshsinghania
@lakshsinghania Жыл бұрын
u need to explore yourself by trying out lot lot lot of problems on cf,cc,sj etc and learning tricks for solving them
@prayasgautam9595
@prayasgautam9595 2 жыл бұрын
This ain't no hack...you just need to be too smart to pull it off. Hats off Striver !!!!!!!!!!!
@noobCoder26
@noobCoder26 Жыл бұрын
thanks Striver , I am learning the whole Graph from your awsome series ✨✨
@dhruvsolanki4473
@dhruvsolanki4473 10 ай бұрын
Very amazing explanation.
@neymarfan4023
@neymarfan4023 Жыл бұрын
Bro now way I am solving this question in a 45 min interview using this techinque lol. Altho I might as well learn for cp
@AshwinHarish-u4t
@AshwinHarish-u4t Жыл бұрын
Thank you for the great explanation sir Sir, can you please tell me why this approach should not be used in interview??
@akshayanm
@akshayanm Жыл бұрын
I've never seen a question like this before. It feels great to submit this solution
@pulkitgupta669
@pulkitgupta669 Жыл бұрын
Thanks Striver. Understood. I have recently started competetive programming so I want to understand this approach. I am learning a lot.
@atulwadhwa192
@atulwadhwa192 2 жыл бұрын
Surely deserve a like on this brilliant explanation tho I'm not in cp much but understood every bit of it.
@stith_pragya
@stith_pragya 9 ай бұрын
Understood............Thank You So Much for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@idlegaming1
@idlegaming1 Жыл бұрын
this approach is easy understandable then previous one
@yashshukla1637
@yashshukla1637 Ай бұрын
really great concept. must know for your google interviews.
@pulkitjain5159
@pulkitjain5159 2 жыл бұрын
amazing approach , found new way of approaching a problem. Thank you Bhaiya!!
@tejpratap9051
@tejpratap9051 2 жыл бұрын
Hey striver, when will you upload the next set of videos, I'm eagerly waiting.
@Ankit.yt_885
@Ankit.yt_885 2 жыл бұрын
Bhaiya Amazing content ! Baaki ki videos kab tak upload hojaegi can you please tell an expected date?
@coding8000
@coding8000 Жыл бұрын
I am ready to help and die for you till my last breath, you are my man
@saranghae3720
@saranghae3720 2 жыл бұрын
U never failed to amaze me 🌻 P.S Just Striver things
@TechieClasher
@TechieClasher 6 ай бұрын
Hey striver, The link to this video is not given in the atoz sheet, the world ladder I video link itself is given for word ladder II video. Thanks for the content.
@cinime
@cinime 2 жыл бұрын
Understood! Another super amazing explanation as always, thank you very much!!
@crazyduniya128
@crazyduniya128 Жыл бұрын
ohhh!! mera to dimag hi hil gya 🤯🤯
@ashutoshanandsharma007
@ashutoshanandsharma007 2 жыл бұрын
Waiting for the new videos of this series❤. I hope you will upload them soon.
@appleinc.2325
@appleinc.2325 Жыл бұрын
love you sir, you are the real saver for us. 🤩🤩
@Rajat_maurya
@Rajat_maurya 2 жыл бұрын
Any update for videos delay bhaiya?
@dhirajsonawane3720
@dhirajsonawane3720 2 жыл бұрын
sir ji sabse jyada wait apke next video ka horaha hain. I hope it will come soon
@Werewolf5684
@Werewolf5684 11 ай бұрын
I would not recomend to skip this, specially when you are preparing for Goolge
@visheshkaran7083
@visheshkaran7083 2 жыл бұрын
Understood😇
@gsmdfaheem
@gsmdfaheem 2 жыл бұрын
Bhaiya new videos kab aayengi? Eagerly waiting....
@gangsta_coder_12
@gangsta_coder_12 2 жыл бұрын
Understood 🔥🔥🔥
@anandA3b
@anandA3b Жыл бұрын
this was actually easier than the first approach
@imPriyansh77
@imPriyansh77 8 ай бұрын
yes, & the logic of starting from endWord towards the beginWord is also helpful..
@Saurav_Kumar514
@Saurav_Kumar514 2 жыл бұрын
Just Wow 🔥🔥
@bhanupratapsharma6158
@bhanupratapsharma6158 2 жыл бұрын
bhaiya iske baad next series kiska hoga toda cp ka bhi topic daal do segment tree ya cp sheet which help alot
@vikaskumar5066
@vikaskumar5066 2 жыл бұрын
Ha bhaiya
@vikaskumar5066
@vikaskumar5066 2 жыл бұрын
Jaise cp sheet
@vikaskumar5066
@vikaskumar5066 2 жыл бұрын
Ya string suffix
@aadipaadi9146
@aadipaadi9146 2 жыл бұрын
Ha bhaiya cp sheet yaha to samjh aa jata leetcode ke vhi ho jaate hai magar codeforces ke nahi hote Phir problem aati hai cp sheet
@rinaksharma7596
@rinaksharma7596 2 жыл бұрын
Cp sheet is best in which topics with question are seperated
@balakrishnanr648
@balakrishnanr648 2 жыл бұрын
understood, but please say the time and space complexity also. Is it O(N*M*26)
@Yash-uk8ib
@Yash-uk8ib Жыл бұрын
Sir, for dfs part, instead of changing character, u could have simply traversed 9n decreasing min value... again saving time and space.
@chinthalatejeswarreddy1026
@chinthalatejeswarreddy1026 10 ай бұрын
In the base case of recursive function dfs we need to add a condition that what ever the sequence that we are getting it has to be the same length of the sequence that we had at the first sequence in the ans vector
@imPriyansh77
@imPriyansh77 8 ай бұрын
No, it's not required, we are adding elements in seq vector only when they are present in the map & are of one small level than the word from which they have been transformed
@shivam-shah
@shivam-shah Жыл бұрын
Correct me if I am wrong but isn't this question using dynamic programming in graph and using the same technique like printing the longest increasing subsequence problem in DP .
@lucygaming9726
@lucygaming9726 Жыл бұрын
I thought so too. Looks exactly like LIS, but here we are not simply decrementing level and iterating over map.
@ITSuyashTiwari
@ITSuyashTiwari 3 ай бұрын
i loved the solution
@guptafactory
@guptafactory Жыл бұрын
Instead of reversing the Sequence vectors in last DFS call, we can reverse it just before return of Ans. for(vector &vec : ans) reverse(vec.begin(), vec.end()); return ans;
@beinghappy9223
@beinghappy9223 2 жыл бұрын
In C++ it is always private by default , why do you write private everytime ? Is it related to some good code practices?
@imPriyansh77
@imPriyansh77 8 ай бұрын
Yes, you're right that private is by default. He is writing private, as he is showing how to write a code in an interview. Writing industry level codes in interview is good
@tanaysingh5348
@tanaysingh5348 2 жыл бұрын
can't praise you enough
@Chandraprakash-kx4ic
@Chandraprakash-kx4ic 2 жыл бұрын
step_1 time 2:08 step_2 time - 5:46 why did this code run and not the previous - 11:32
@vaibhavagarwal2421
@vaibhavagarwal2421 Жыл бұрын
this is more intuitive to me than storing vector of strings in a queue
@imPriyansh77
@imPriyansh77 8 ай бұрын
Yeah
@aaaaz424
@aaaaz424 Жыл бұрын
Striver! I have a genuine question. I am a working professional. What is the upside of doing competitive programming for those who are already working? Should I focus more in development ?
@UECAshutoshKumar
@UECAshutoshKumar Жыл бұрын
Thank you sir 🙏
@vakhariyajay2224
@vakhariyajay2224 2 жыл бұрын
Thank you very much. You are a genius.
@ritikshrivastava9442
@ritikshrivastava9442 9 ай бұрын
one question = while erasing we are checking if(st.count(word)) means the word should be present then only erase, let's say we erased endWord, and now for calling dfs we are checking endword should be present if we have already erased it while pushing how it can be present beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"] do dry run for this
@VishaliniT-f3g
@VishaliniT-f3g 6 ай бұрын
Understood 😊
@abhishek__anand__
@abhishek__anand__ Жыл бұрын
Great Explanation
@mrtuyiop
@mrtuyiop 7 ай бұрын
What if we wanted to wanted to find only one possible combination in best space complexity
@AbhavGoel
@AbhavGoel Жыл бұрын
in the dfs fucntion cant we iterate over the map and look for the words with one step less than current word and apply dfs on them. It would reduce the computations for trying all words in the dfs
@lucygaming9726
@lucygaming9726 Жыл бұрын
We can't because we have to figure out the right sequence. Look at the example he gave and try this once.
@Rajat_maurya
@Rajat_maurya 2 жыл бұрын
Sir code not working only 32 out of 36 test case are passing?
@RitikRaj-we2sc
@RitikRaj-we2sc 2 жыл бұрын
i am not able to understand one thing, that why previous solution gave TLE, because there too we were trying all the possible combination of word, and same is being done here. Someone please explain this.
@ApoorvBedmutha
@ApoorvBedmutha 6 ай бұрын
This guy is my god
@noobCoder26
@noobCoder26 Жыл бұрын
i dont know why I felt this approach slightly easier than earlier 🎃🎃
@GyaanGrave
@GyaanGrave 2 жыл бұрын
preparing for interviews only but still watched it out of greed for problem solving ability even after you telling not to watch it 😎
@rachit2982
@rachit2982 2 жыл бұрын
Please make a video solution on word wrap problem given on gfg and please explain both solutions (space optimised and brute force)
@NARUTOUZUMAKI-bk4nx
@NARUTOUZUMAKI-bk4nx Жыл бұрын
understood class Solution { public: map mp; void dfs(string endWord,string beginWord, vector &vec,vector &vs){ if(endWord==beginWord){ reverse(vs.begin(),vs.end()); vec.push_back(vs); reverse(vs.begin(),vs.end()); return; } for(int j=0;j
@sanjayp.m7008
@sanjayp.m7008 5 ай бұрын
This one seems more intutive for me, but y shld i not say this in interviews?
@piyushgoel3020
@piyushgoel3020 Жыл бұрын
thank you striver
@suryakiran2970
@suryakiran2970 Жыл бұрын
Understood❤
@The_Shubham_Soni
@The_Shubham_Soni Жыл бұрын
UNDERSTOOD.
@anonymous-ms2en
@anonymous-ms2en 2 жыл бұрын
@Striver bhaiya os,dbms and oops topics ki bhi playlist bna do plzz
@vaarigupta6332
@vaarigupta6332 Жыл бұрын
I think that the optimized approach is better than this one. This seem to be bit complicated but the optimized approach seems to be an extension of word ladder 1 so that seems to be good approach than this one.
@prathamsharma4416
@prathamsharma4416 Жыл бұрын
Striver, a big W
@p38_amankuldeep75
@p38_amankuldeep75 2 жыл бұрын
understood❤❤❤
@suhasdevang9332
@suhasdevang9332 2 жыл бұрын
striver brother pls make a video about when the top tech company hiring start in 2022 and some tips to get shortlisted... please brother
@sakshisinghal1669
@sakshisinghal1669 2 жыл бұрын
Hey @Striver can you also cover floyd warshall?
@takeUforward
@takeUforward 2 жыл бұрын
I will.
@Learnprogramming-q7f
@Learnprogramming-q7f 8 ай бұрын
Thank you bhaiya
@ADITYAKUMAR-tb4gm
@ADITYAKUMAR-tb4gm 2 жыл бұрын
understood
@madhurgupta4220
@madhurgupta4220 2 жыл бұрын
Understood !
@bhavya8608
@bhavya8608 Жыл бұрын
understoodd!!!
@nishantdhamija2880
@nishantdhamija2880 2 жыл бұрын
Understood how many more videos of this series
@HimanshuGupta-ni3pk
@HimanshuGupta-ni3pk 2 жыл бұрын
Yeh kon sa series ka hai ?
@nishantdhamija2880
@nishantdhamija2880 2 жыл бұрын
@@HimanshuGupta-ni3pk graph
@krishanpratap3286
@krishanpratap3286 2 жыл бұрын
Maja aa gaya bhayiya us*3
@ayushjain386
@ayushjain386 2 жыл бұрын
Next videos kb aari hai ?
@gametech7046
@gametech7046 2 жыл бұрын
Bhaiya union find pe videos nahi aengi kya? Mene A-Z sheet check kiya lekin usme Union Find covered nahi hai 😔
@harshdasila6680
@harshdasila6680 2 жыл бұрын
bhaiya saari videos aa gyi h ya abhi aur baki h??
@valarmorghulis9244
@valarmorghulis9244 Жыл бұрын
Bro Can we not show this solution in an interview. It seems to be more easily explainable then the previous one.
@vishichaurasiya4427
@vishichaurasiya4427 Ай бұрын
15:08
@edu3956
@edu3956 2 жыл бұрын
What's happen? Why not uploading bro?
@GauravKumar-by1yt
@GauravKumar-by1yt 2 жыл бұрын
Understood
@KratosProton
@KratosProton 2 жыл бұрын
great
@ashutosh..
@ashutosh.. Жыл бұрын
What's the cp thing in this?
@yashshukla1637
@yashshukla1637 Ай бұрын
One notes added
@amiteshshekhar601
@amiteshshekhar601 2 жыл бұрын
when will you start uploading videos for dsa from starting
G-30. Word Ladder - 2 | Shortest Paths
25:42
take U forward
Рет қаралды 155 М.
人是不能做到吗?#火影忍者 #家人  #佐助
00:20
火影忍者一家
Рет қаралды 20 МЛН
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 828 М.
G-29. Word Ladder - I | Shortest Paths
28:07
take U forward
Рет қаралды 241 М.
167. Two Sum II - Input Array Is Sorted
8:21
Siddharth Nagaych
Рет қаралды 46
G-41. Bellman Ford Algorithm
27:43
take U forward
Рет қаралды 258 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 249 М.
G-54. Strongly Connected Components - Kosaraju's Algorithm
22:44
take U forward
Рет қаралды 160 М.
G-46. Disjoint Set | Union by Rank | Union by Size | Path Compression
42:15
G-42. Floyd Warshall Algorithm
30:13
take U forward
Рет қаралды 251 М.
G-20. Find Eventual Safe States - DFS
23:43
take U forward
Рет қаралды 198 М.
G-45. Prim's Algorithm - Minimum Spanning Tree - C++ and Java
19:10
take U forward
Рет қаралды 300 М.