That intro tho LMAOOOO!..keep up the good work bro! you bring life to Leetcode problems!
@ik60715 жыл бұрын
I’m struggling doing these questions and I’m starting to lose hope
@NickWhite5 жыл бұрын
nooooo ! this is a medium problem! Do some easy ones
@mh92154 жыл бұрын
Keep at it, its difficult for everyone. The hard work will pay off :)
@ansuman42334 жыл бұрын
You will get there! Trust me. When I started off reading through questions like these a month ago, it was so overwhelming and when you keep doing(trying) to solve problems (starting from easy and upwards) your brain would automatically find the pattern. I don't how it works but that's true! A month ago, I would have never thought of doing a BFS on this array but when I started with this problem today, the voice inside my head automatically went USE BFS! Although my answer did not pass all the test cases, I was elated that I could think of an approach! I hope you get to read this and keep practicing and never give up! and thanks Nick, you're a rockstar!
@varunrao21354 жыл бұрын
learn fundamentals before doing random questions and feeling like u have no hope. every questiono has like 4 -5 underlying topics in it. learn those, learn the techniques do them well and come back to it.
@nirmalkumarsahoo86834 жыл бұрын
Thanks Nick.
@akshaygupta43494 жыл бұрын
Nick, Thank You for the video. It would be really helpful if you could also talk about the space and time complexity associated with each solution.
@iamjiaji5 жыл бұрын
Line 22, should be c
@NickWhite5 жыл бұрын
yeah that was an accident my bad
@iamjiaji5 жыл бұрын
@@NickWhite Thanks for the solution!
@IWantSoundKnowledge4 жыл бұрын
They updated the test cases on leetcode. Now they include 'z'
@nehalshrivashtava11694 жыл бұрын
@@NickWhite your LinkedIn URL is wrong I guess... btw thanx for this video
@surajitpaul3 жыл бұрын
@@NickWhite Thanks for creating the videos, these hiccups actually help in learning process!
@pubamx4 жыл бұрын
Hey man, I think you could save the first for loop by just declaring the set like this: Set wordSet = new HashSet(wordList);
@willinton064 жыл бұрын
Loop still there just behind the function, unless some pointer arithmetics are being used, doing the loop will save you some time
@MehediHasan-tm8ek3 жыл бұрын
Thanks, Nick But I think loop will be *for (char c = 'a'; c
@jeffreylee9113 жыл бұрын
for (char c = 'a'; c
@karthikbhat1814 жыл бұрын
Hey Nick! In the 3rd for-loop, where you iterate over all the characters from 'a' to 'z', shouldn't it be from (c='a') to (c
@johnnydoey79204 жыл бұрын
Yea I tried his code out but failed one test case then I changed (c
@Jing342714 жыл бұрын
@@johnnydoey7920 you are the smart guy
@terrypbark4 жыл бұрын
What is the time complexity of this?
@ayushthakur-be2lr2 жыл бұрын
The char loop should be from c = 'a' to c
@alekseidanilov92795 жыл бұрын
hi Nick, thank you for video, great explanation. But why for loop from c = 'a' to c < 'z' (not inclusive 'z')?
@NickWhite5 жыл бұрын
accident! Good catch that’s my bad!
@sumitanglekar63094 жыл бұрын
Thanks for clearing this out. I was struggling for a while when I decided to look into the comments for an answer!
@tejasjain70974 жыл бұрын
Test cases have been changed now fam, Don't forget the
@PritamKarmakar4 жыл бұрын
Great explanation as always. Do you mind posting a video for Word Ladder II problem?
@pradeeptiwari41934 жыл бұрын
I did that last night - Exactly same thing but maintain the list of list of words already accounted
@codewithjc46174 жыл бұрын
I got this question on a Facebook Interview a year ago
The first thing when i search for any leetcode question's answer is either Nick White's Solution or Tushar Roy's.
@akshaywaghela86474 жыл бұрын
Output is 0 instead of 10 for the below input. 42/43 test cases passed. "ymain" "oecij" ["ymann","yycrj","oecij","ymcnj","yzcrj","yycij","xecij","yecij","ymanj","yzcnj","ymain"]
@Jing342714 жыл бұрын
change (c='a') to (c
@akshaywaghela86474 жыл бұрын
@@Jing34271 it was a
@nagalakshmichithambaranath11474 жыл бұрын
You made the difficult to sound very simple to solve. Your videos are really cool. Thanks!
@lakshaysharma86054 жыл бұрын
Man, you are just awesome. Your Explanation of the question just hit the nail on the head. Keep Going !!
@shreyamduttagupta75274 жыл бұрын
any idea about the time complexity?
@vanapallisuryanaryana88814 жыл бұрын
def ladderLen(beginWord, endWord, wordList): if endWord not in wordList: return 0 queue = collections.deque([(beginWord, 1)]) wordmap = {} while queue: word, level = queue.popleft() if word == endWord: return level for hop in wordList: if 2 == len(set(hop).intersection(set(word))): if hop not in wordmap: wordmap[hop] = None queue.append((hop, level+1)) return 0
@MistaT444 жыл бұрын
The use of snake case and camel case triggers ocd. Haha but jokes aside, awesome video as always Nick! This was a tricky problem
@TheDannyDeez5 жыл бұрын
Good shit nick, good shit.
4 жыл бұрын
shouldn't the condition on line 23 be: if (word_chars[j] == original_char) continue; ? It doesn't make much sense to me as it is.
@andresalba343 жыл бұрын
If I see this problem in an interview , I'll just get up and change careers 😅
@heisenberg18444 жыл бұрын
Thanks to you, I've mastered BFS. B)
@MGtvMusic3 жыл бұрын
hahaha same
@omkarvaidya60774 жыл бұрын
Nice explanation. Thanks, Nick. It would be also helpful if you could discuss the time and space complexity of the solution at the end. Also, would appreciate it if you could post a video on Word Ladder II as well. Thanks once again.
@tehAmaazingSheikh4 жыл бұрын
It would be nice to see the raw video with the mistakes so we could see your thought process when you reach a wall
@raghuramanswaminathan51874 жыл бұрын
Beautifully explained Solution Nick! Thank you so much.
@gauravvarshneya67615 жыл бұрын
Great explanation! One question though, why do you remove the word from the set? Wouldn’t you want to keep it since you’re not sure yet if that’s the path you want to take to find the EndWord? Example: .........”hall”>“ball”>”wall”>”walk” .........“hall”>”wall”>”walk” In the above example, if you remove “wall” from the set in the first line, how would the second line work since that should be the shortest path?
@lifehacks94504 жыл бұрын
Because in the first iteration The word wall would have been added to the queue so when we will pop out that word wall we will get walk and ans would be 3
@mohammedsadiq15675 жыл бұрын
Hey Nick, Will you please help me solve this one? Determine how "out of order" a list is by writing a function that returns the number of inversions in that list. Two elements of a list L[i] and L[j] form an inversion if L[i] < L[j] but i > j. For example, the list [5, 4, 3, 2, 1] has 10 inversions since every element is out of order. The list [2, 1, 4,3, 5] has two inversions: (2, 1) and (4,3). Do this in better than O(N^2).
@NickWhite5 жыл бұрын
sounds like count inversions which can be implemented using a divide and conquer approach and can run in NLogN time
@NickWhite5 жыл бұрын
just look up “count inversions solution” on google and you’ll find something
@mohammedsadiq15675 жыл бұрын
@@NickWhite Got it thank you.....!!
@FabioLux3 жыл бұрын
Funny to see that they changed the problem difficulty from medium to hard
@mostafamohsen2504 жыл бұрын
I think the first for loop in the while loop is unnecessary, wouldn't this solution still work without it?
@willinton064 жыл бұрын
Can’t you just loop through the words and have a counter of letters that are different? If the counter returns 1 you know it’s a transformation and if it returns more it’s just different
@SolutionHunterz4 жыл бұрын
Thanks for posting videos, However it would be great to go over the different solutions and their time and space complexity. That would help a lot.
@muskangupta75224 жыл бұрын
can you also add 126 word ladder problem (hard version) , where we have to return the list of all sequences from begin to end node ...
@arnabpersonal67293 жыл бұрын
You can avoid the loop having 0 to size
@andresm-pf9ij2 жыл бұрын
Hey Nick ty for the video, how this is ensuring this is the shortest path?
@tathagatnegi59234 жыл бұрын
Congrats for the 80k buddy👍.. 100k soon
@spectermakoto90294 жыл бұрын
Do you really gotta cycle through the entire alphabet just to solve this problem?
@mastaharashibu70924 жыл бұрын
I was thinking the same thing. I feel like there should be a better time complexity option for this but honestly I can't think of one.
@awekeningbro12073 жыл бұрын
we can create a data structure that will contains 2d array like this: [ [h,d,l,c], [o], [t,g] ] each row index would correspond to the current index of the word and the letters inside each list can be iterated to check and swap to create a word if it exists in the dictionary.
@davemustainejigsaw4 жыл бұрын
I can understand that this would help in finding if there's a possible way to get to the end word from the beginning word. But I'm not sure how it gives the shortest transformation? p.s: the intro --> 🔥
@davemustainejigsaw4 жыл бұрын
Oh, my bad i guess it' coz, you'd be at the same level with the sibling nodes... I see. Sorry about that!
@mridulchaudhary85453 жыл бұрын
This questions has been labelled "Hard" now
@nickv87074 жыл бұрын
Only reason to copy data to Set was to use contains and remove methods in O(1) time
@secularph84244 жыл бұрын
Python strings are too immutable
@beautifulmind6844 жыл бұрын
Hi, thx for your explanation, I'm wondering what recorder you were using in this video? looks like you got extra camera....
@MohitSinha44 жыл бұрын
Thats a very nice explanation, thanks!
@obidulislam16573 жыл бұрын
I am not sure how your code got accepted when the character replacement loop at line 22 doesn't include char 'z'. It should be
@uwontlikeit4 жыл бұрын
Does it even work? This way of Level counting in BFS does not make any sense to me
@boredasever66454 жыл бұрын
Not going to lie, idk if this solution would be good enough for an interview. This runtime is really really bad.
@bronsonschnitzel74934 жыл бұрын
this is fine for interviews...
@artofwrick9 ай бұрын
It is bfs. There's nothing to shy about time complexity. It's all the same and everybody knows that
@pratheek50964 жыл бұрын
Could have just called a different function to check if the curr_word differs from the word being evaluated by one character or more
@jayeshpokharkar27084 жыл бұрын
Why do we need set.remove(new_word); ? There will not be duplicates as the character loop is going from a to z.
@imkrrishnayak4 жыл бұрын
great explanation! keep up the good work!
@pratheek50964 жыл бұрын
They have mentioned to assume no duplicates...set is unnecessary right? Since List supports .contains() and .remove() methods ?
@za39314 жыл бұрын
contains and remove take O(n) so set is necessary af.
@TeluguUSDiaries4 жыл бұрын
WordLadder II, please?
@gloriasingh85162 жыл бұрын
what is the Time complexity here? Can anyone tell?
@sparkle30242 жыл бұрын
the intro gave me a heart attack
@arbazshaikh44474 жыл бұрын
Hey good explanation! what is the time & space complexity ?
@mrprime5572 жыл бұрын
O(M^2*N) where M is the length of the word and N is number of words.
@akil1991gen3 жыл бұрын
it should be c
@kavyatsaliki46424 жыл бұрын
Please do word ladder ii @nickwhite
@kamalpreetsingh47824 жыл бұрын
Best intro😂😂
@ahnaf77khan114 жыл бұрын
The intro is cringy. But as always his contents are the best.
@df56493 жыл бұрын
how about ["a","b","c"]. Should be 2 levels,but turns to one if a transforms to c
@pujamishra14754 жыл бұрын
I'm struggling to understand why I get "Wrong Answer" when I use queue.size() in the for loop constraint and not use a size variable to assign the queue size before and then run for loop size times. Code shown below: //loop through the queue until empty while(!queue.isEmpty()){ for(int i = 0; i < queue.size(); i++){ // Here if I assign int size = queue.size() before for loop I get the correct answer. String curr_word = queue.poll(); //// Thanks in advance.
@bronsonschnitzel74934 жыл бұрын
queue is changing in size with every step of that iteration. Every time queue.poll() is called, queue.size() will change. you need to assign the size to a variable to retain the BFS level size.
@pujamishra14754 жыл бұрын
@@bronsonschnitzel7493 Thanks a lot for your reply. This really cleared the confusion I had.
@f3-faithfitnessfinance5 жыл бұрын
Definitely first!
@PedroTechnologies3 жыл бұрын
Bruh cant believe I found you here lmaooo
@f3-faithfitnessfinance3 жыл бұрын
@@PedroTechnologies Hahaha😂😂😂 I am everywhere lol You have any interviews soon?
@PedroTechnologies3 жыл бұрын
@@f3-faithfitnessfinance Have an interview next week for an internship. Might make a video about it if I get the offer!
@f3-faithfitnessfinance3 жыл бұрын
@@PedroTechnologies Woohoo All the best bro🙌👍 Kill it🔥
@haojia63084 жыл бұрын
Hi Nick, I can do it by iteration but I am struggling why I cant do it in recursion. Any idea how to do it in recursion?
@kushagrakulshrestha29668 күн бұрын
WTF DUDE lol ... never seen you give intro like this :D
@lifehacks94504 жыл бұрын
Pls upload questions on Prim's and kruskal algo
@deeproy72924 жыл бұрын
poll and offer...and loved the solution
@Marina_DU3 жыл бұрын
Aquí está la fiesta 🥳🎊🎉
@alvxlopez4 жыл бұрын
Thank you!
@Haylem3 жыл бұрын
did not expect you to say N-Word. WOW
@mukundsridhar4250 Жыл бұрын
you do a great impression of someone who is high
@abdusalam3ar4 жыл бұрын
I thought you were high at first hahaha
@rachitagrawal35703 жыл бұрын
Coding problems and interview are literally broken sometimes. 😢
@ankursuri38534 жыл бұрын
You are the best!
@TravelwithPanchi5 жыл бұрын
What is the time complexity?
@meetnikhil7194 жыл бұрын
What would the time complexity be for this?
@AmolGautam5 жыл бұрын
Thank you so much
@NikhilVerma-kc3io3 жыл бұрын
what would be the time complexity of the above solutions?
@mtvmango51722 жыл бұрын
Is worst case time complexity for this solution M+26*n*M?
@mdzikrullah95753 жыл бұрын
nice explanation
@iamabean4 жыл бұрын
is it similar to edit distance problem in Dynamic programming
@koga73494 жыл бұрын
Looping through the alphabet is not necessary and doesn't scale. What if the word is 5 letters long? You're brute forcing every possible 5 letter word. The runtime would be 26^5 or 11,881,376 iterations. Not to mention that we are already nested in multiple other loops. Instead just compare letter differences between your current word and dictionary words. If only one letter is different then the path is valid
@mnchester2 жыл бұрын
great video!
@shubhamnaik19824 жыл бұрын
what was that in the initial , too funny
@dipteshsil92994 жыл бұрын
What is the time complexity of this code?
@ashishbarai14254 жыл бұрын
Best in you tube 👍
@conf494 жыл бұрын
What would be the time Complexity here?
@artofwrick9 ай бұрын
Medium?? Where are you?
@ousmand7424 жыл бұрын
why did he remove the word on line 29 from the set
@v.smourya80054 жыл бұрын
it's like marking visited what we already explored so that we don't move backward in our search. hit --> hot if you don't remove the word "hit" from the set, you would revisit "hit" again when exploring "hot". what you don't want : hit --> hot --> hit --> hot --> hit --> hot ...
@anneheaven01233 жыл бұрын
I tried the same solution on Leetcode and the output is wrong. Could someone please tell me what I did wrong? Did I miss something or did the problem statement change? :'( class Solution { public int ladderLength(String beginWord, String endWord, List wordList) { HashSet set=new HashSet(); for(String s: wordList) { set.add(s); System.out.print(s); } if(!set.contains(endWord)) return 0; Queue q=new LinkedList(); q.offer(beginWord); int level=1; while(!q.isEmpty()) { int size=q.size(); for(int i=0;i
@HiBMlive3 жыл бұрын
you have written return level++; whereas it should be level++ only
@anneheaven01233 жыл бұрын
@@HiBMlive shows "Output limit exceeded" for input "zings" "brown"
@HiBMlive3 жыл бұрын
@@anneheaven0123 remove the System.out.println lines and it should work
@anneheaven01233 жыл бұрын
@@HiBMlive That helped. Thank you!
@chodingninjas74155 жыл бұрын
great.
@chanduc20004 жыл бұрын
nice, it's Ok
@baibhavghimire38273 жыл бұрын
First for loop seems unnecessary.
@monkyyy04 жыл бұрын
>never again Please again
@__nitinkumar__2 жыл бұрын
That intro 🤣🤣
@lemp95823 жыл бұрын
Nick did you find a job?
@zyjian1921 Жыл бұрын
this is hard for sure.
@unknownman1 Жыл бұрын
it is not in hard :)
@emp_3334 жыл бұрын
Should be a hard really.
@treeduck9992 жыл бұрын
That loop trough the alphabet is atrocious
@AlexandrBorschchev3 жыл бұрын
Code is not as helpful as explaining it. Please sketch your thoughts as that would be more intuitive.