No one explains solutions better than you, thank you so much for these videos, they are helping me a lot in the process of getting ready for technical interviews!
@NickWhite5 жыл бұрын
thanks
@joanmoralesf2 жыл бұрын
Its insane how short this video is but you explained it better than all the long fancy videos. Thank you
@jay-wf3ft4 жыл бұрын
I think it would be great if you would show 2 solutions. One with a slow run time and then the optimal solution such as this. It really helps to understand it even more. Either way awesome video
@pritampadhan59772 жыл бұрын
Above logic takes more time i think
@vcfirefox3 жыл бұрын
Dude, I am probably much older than you, but goddamn I am LOVING your explanations. Getting a chance to prep my interviews very efficiently!
@KhayamGondal2 жыл бұрын
you can add a check for prefix length ==0 at the end of the while loop. Incase nothing matches with the 2nd string then no need to check with rest of the list. And instead of substringing every itteration you can keep track of right index and only substring when returning the result.
@raghavendrathakur22392 жыл бұрын
@bhargavvaddepally32214 жыл бұрын
Damn man that explanation was so smooth
@ananyadutta63583 жыл бұрын
bro your explaining method is quite creative , out of 7 videos based on this that I'd WATCHED , this was the best!
@prajwalshenoy91173 жыл бұрын
Nice one. We can have a case inside for loop to break it when prefix length reaches zero to avoid continuing to loop when there's no scope of common prefix further.
@poojaupadhyay63644 жыл бұрын
such a clear approach! everytime i do leetcode and feel like wtf about a question ,i come here to watch your tutorial and i understand the solution so clearly! thanks a lot,u have a great help dude!
@suyogsubedi85843 жыл бұрын
are you a better problem solver by now?
@aadhi_dinesh76682 жыл бұрын
IN PYTHON s=["flow","flew","flower"] k=s[0] flag=0 a="" for x in range(len(k)): for j in s[1:]: if k[x]!=j[x]: flag=1 else: a=""+k[x] if flag==1: break else: print(a,end="")
@himanshumalik69133 жыл бұрын
You know what, you just explained in a so easier way that no one has explained yet.
@satyamgupta6030 Жыл бұрын
what a solution man thanks alot nick brother please continue making these videos. u r just different when it comes to explaining in most optimised ways.
@vicente3j2 жыл бұрын
When I search up a leetcode question I always go to Nick White if its available 😂 Great video
@6066ChetanKhairnar3 жыл бұрын
got through 3 different videos for a good solution but nick is one who always gives the best approach , Appreciate bro
@abdelghafourboufenzi2139 ай бұрын
but this is incorrect in the case of : "abower","flower","flightwer" the result should be "wer" but the result is empty.
@syedrehan32518 ай бұрын
Bro prefix means starting of the letter
@simrankak70453 жыл бұрын
Why i didnt find your channel until now. Your explaination is crisp clear and very simple thankyou :)
@greatred25583 жыл бұрын
thanks, tried many things for c# but kept falling out of bounds. This works and simple to understand
@brucewayne94444 жыл бұрын
Wow man. I could have never thought of approaching this problem this way. Thanks a ton👍
@nurulloabdurakhmanov49142 жыл бұрын
Exactly man. What should we do to get into thinking like these aproaches ?
@ashish4k0711 ай бұрын
I thought of using 1st string in array of string as base and scanned through all others and checked if one by one it matches all other strings if it is then we increment the string and hence getting final lcp ans
@utkarshsrivastava3114 Жыл бұрын
What a clean and simple approach
@sreenidhisreesha2 жыл бұрын
Since indexOf is linear time complexity, Doesnt it make this O(n2) time complexity?
@tanyagoel91404 жыл бұрын
It was so nicely explained. Thanks a lot!
@prathamchitransh53382 жыл бұрын
best explaination for this problem on youtube
@hbrymiri8301 Жыл бұрын
Hands best step by step explanation.
@headyshotta57772 жыл бұрын
Thanks for the explanation. I still don't really understand how your while loop works but I'll keep working to understand.
@carefree_ladka2 жыл бұрын
indexOf() takes O(N) time . How is your method linear?
@saradham28443 жыл бұрын
Best solution for this problem . Great approach and clear explanation Thanks !!!
@Noname-di3yz2 жыл бұрын
the only thing I don't understand is why we can set the first element as the prefix initially... isn't it possible that there is a different longest prefix? ex/ ["ab", "cd", "cde", "cdef","cdefg"], where if we set the prefix to "ab" wouldn't your solution return "" ?
@syc4654 Жыл бұрын
probably very late but although the problem doesn't mention it specifically,longest common means that the common prefix must be common for all the elements in the array,so yes,"" would be returned and it would be correct,you can test it yourself inputting your string own string in the Testcase section(In the console) and seeing the expected resulted (from a working code) and your result (from your code)
@kshitijpandey93763 жыл бұрын
You wrapped that up very smoothly. Thanks Nick🙂.
@divyanshuchaudhari54162 ай бұрын
Great explanation Nick!! Kudos to you.
@tej36792 жыл бұрын
best explanation, you explained clearly kudos
@dgr8raka4702 жыл бұрын
I think in place of “indexOf” .. we need to use “startswith” method… tq for the vdo
@velmuruganjeyakumar17462 жыл бұрын
Yooo Man , I too had that same feeling
@balavardhanreddy8581 Жыл бұрын
by watching this video i subscribed ur channel
@thomasgeorge45783 жыл бұрын
Man! your explanation is just fire 🔥🔥🔥
@solomonmokua46432 жыл бұрын
Than you, well explained, was able to implement your solution in Python.
@flyfly111112 жыл бұрын
You explained it very nicely. Thank you so much
@gayan17423 жыл бұрын
Time complexity of indexOf is O(n) though.
@Ben-pb7ct3 жыл бұрын
Could you explain why the time complexity is O(S), where S is the sum of all characters in all strings?
@maxstanley18183 жыл бұрын
yo but what if the first element in the "fl" prefix array is something like "dog" or something?
@Thrallgg3 жыл бұрын
str.indexOf and str.subStr is O(m*n) i think, so I don't think it's optimal.
@tuckerleavitt3 жыл бұрын
Yes you're correct, a.indexOf(b) is O(len(a) *len(b)) in the worst case. There is a better solution
@pranaychoubey97063 жыл бұрын
you can eventually shift to stringbuilder i guess.
@ashish4k0711 ай бұрын
So can what can be the overall time complexity for this
@invictuswildlife4 жыл бұрын
Kudos to such a clean explanation ! Thank you.
@ehsanhosseini58614 жыл бұрын
Thank you for this amazing explanation. What is the time complexity?
@royt69243 жыл бұрын
I believe it is O(A*S) where A is the iteration for each element of array, where S for the iteration of string
@amitpadaliya69165 жыл бұрын
really amazing solution
@zerosandones75472 жыл бұрын
confusion.Cleared(); THANK YOU!
@AlejandroRodriguez-lq9mz4 жыл бұрын
thanks for sharing such solution, very clear and easy one!
@abhishekmamgain2242 жыл бұрын
Still you are using While loop and one for-loop. Wouldn't this make the time complexity similar as two for-loops
@mohammadrafi8952 жыл бұрын
No, it wouldn't because the inner loop will not depend on the length of input array. Input array could have 100 words but each word can't be longer than 20 characters, on average 5-10.
@ryan-bo2xi3 жыл бұрын
what is the time complexity ?
@rupaldesai70985 жыл бұрын
the time complexity is? O(n^2)
@NickWhite5 жыл бұрын
Nope because we're not looping through the strs array in the inner loop we're popping characters off of one string
@suryaakella45084 жыл бұрын
@@NickWhite What if all the elements in the string are same like all flowers than no deletion and the time complexity would be O(n^2)? I think we would have to use trie or suffix array to get O(n)?
@i_deepeshmeena4 жыл бұрын
@@suryaakella4508 it will be still O(NM) where M is the length of the longest string in the array
@jardondiego4 жыл бұрын
@@i_deepeshmeena Indeed, time complexity is O(MN) and space complexity is O(M).
@jardondiego4 жыл бұрын
Time complexity with a Trie (prefix tree) would be O(M log N) where M is the length of the longest string and N the number of strings, right?
@mohammadosama47094 жыл бұрын
Why do we need substring method we can check character by character vertically? Wouldn't that me more optimal?
@ricardosmith57532 жыл бұрын
very clean solution.
@thatsenoughdixit Жыл бұрын
Very nice. Commenting so I get more videos.
@rohitkushwaha61252 жыл бұрын
Thank you so much for the explanation ut was really nice.
@pjguitar153 жыл бұрын
I literally got stuck to this problem and I just gave up and went to KZbin lol
@swagatzeher3 жыл бұрын
Thanks man Nick... you are a pocket sized dynamite ;)
@TheRishit992 жыл бұрын
Great explanation. Can solve this with Trie Tree ?
@carefree_ladka2 жыл бұрын
That's the efficient way to solve this problem
@freinheit6923 Жыл бұрын
thank you for explaining!
@abhinavs2484 Жыл бұрын
in worst case it is O^n2 right, is there any better solution!
@KIM-ODee5 ай бұрын
Thanks for your explain!
@pragatikumarprusty70612 жыл бұрын
If possible, please tell the time and space complexity as well ...
@gauravmishra8782 Жыл бұрын
how did you came up with this solution?
@jiangtianfeng59714 жыл бұрын
very clear! Thx man
@adil_k Жыл бұрын
Thanks for this awesome video
@LeetCodeSimplified4 жыл бұрын
Great explanation! Thx a lot!!
@kso3586 Жыл бұрын
Amazing! thank you so much👍
@sameer93685 жыл бұрын
hello....please do the problem on the merging k- sorted array using heap.
@NickWhite5 жыл бұрын
send me a link in discord and i'll check it out
@sameer93685 жыл бұрын
i am solving in eclipse . i have the problem statement. can i share you that problem statement. i dont know the approach how to solve such problem, i am the beginner. also i am unaware of the concept like heap. please do the video on it
@abdulqudusyunus97863 жыл бұрын
Nice explanation
@vidhi_bhatt2 жыл бұрын
simple and on point!
@Whaleshamu5 жыл бұрын
can you make video on Gray code (Leetcode 89)?
@NickWhite5 жыл бұрын
I’ll check it out!
@DevanshuMevada5 жыл бұрын
Thanks Man!
@srijitdebsarma34512 жыл бұрын
Best explanation 😍🥰
@avinashpatil96622 жыл бұрын
What is the time complexity of this solution?
@makgaboemmanuelmathekga2805 Жыл бұрын
the code breaks though, with index out of bound error when there is no common prefix
@shivamd233 жыл бұрын
Best Solution 😊👍
@NeeruSinghK4 жыл бұрын
great.. nice and easy solution
@Post2prqbu4 жыл бұрын
wow! elegant solution!
@iTzAlwxyss3 жыл бұрын
How does this not work for processing 4 that uses java ?
@theolim6994 Жыл бұрын
Thank you so much for great explanation!!! Helped so much!
@habibdurodola57283 жыл бұрын
Best solutions , Yes you did !
@davidc32682 жыл бұрын
how is a linear solution? theres is a nested while loop inside?
@whiz-code4 ай бұрын
You a genius
@ruifan7934 жыл бұрын
Help me a lot, thanks
@Itachibatman2 жыл бұрын
thanks don
@vrindatyagi67444 жыл бұрын
THANKYOU SO MUCH
@gokulkumarbhoomibalan54134 жыл бұрын
Really helpful!
@simardeepkaur82753 жыл бұрын
Thanks buddy
@blaze9558 Жыл бұрын
thanks man!
@swethanooka8962 жыл бұрын
Can anyone explain me the while loop part of the code?
@jasonliu71864 жыл бұрын
Thanks very much!
@ayushbudhwani3 жыл бұрын
Nailed it!!
@fahdagodzo57953 жыл бұрын
This guy is smart
@mohitdangwal5872 жыл бұрын
you the BEST!!!!!!!!!!!!!!!!!
@arjun-cw7cr4 жыл бұрын
thank you
@sarash96072 жыл бұрын
Can anyone tell me why do we set the first string as a prefix ? how do we know it is the longest string and the one that has all the letters that we want ? what if the array was like strs = [ "flight", "flower", "flow"]
@raghavendrathakur22392 жыл бұрын
when program runs it finds common between flight and flower first the common is fl and 2nd iteration it will find common between fl and flow so our aim is to find common in strings so what is there in 1st will be in all the strings if not it returns empty string
@rajeevsingh54534 жыл бұрын
What's the time complexity of this algorithm?
@aryamankukal10563 жыл бұрын
linear
@akhila55973 жыл бұрын
Simply wow
@shastriswaroop4 жыл бұрын
How about setting the prefix as the smallest length string and then starting loop from index 0. For longer string array it will be beneficial?
@MRDELL-mc6zo2 ай бұрын
Thanks Broh
@bty_s3 жыл бұрын
There is no condition that all array items is started by the same prefix, if this prefix is actually exists. i mean the first ex in the lesson is [flower, flow, flight]. fl - longest common prefix. but in case of [flower, flow, flight, tennis, ten, tenet, tent]. ten - longest common. your solution will not work in such case.
@deepanshuyadav68153 жыл бұрын
So how would u do it....
@dannytierney29693 жыл бұрын
Your second example has no common prefix, as three of the words do not share the prefix "ten" At least, that is how the question is set up.