loved your explanation . But 1 thing I would like to correct . The time complexity of method 1 will be O(n k log k ) , where k is the length of the string , n is total strings . This is because sorting a string would take (k log k ) . Any way awesome explanation . thanks
sir you explaination to any algorithm is the best explanation i had ever seen ...only your explanation is enough to solve the problem no need to see the code
Hey, I found this video trough the article and thank you for all the work, it really helped me. The solution of method 2 at line 34 has a mistake: "freq++;", you can't ++ an array, so we need to do freq[c - 'a']++ :)
I don't know why, I ran both techniques sorting and frequency but sorting is showing less time than frequency method. sorting => 15ms frequency = 29ms. I believe its random.
@@shaileshsathe9779 I'm not sure but I think it might be because frequency string has to be sorted so it takes even longer to count everything and sort the letters alphabetically
8:14 should be "nat", not sorted string "ant". Otherwise your tutorials are the best regarding leetcode problems, because you explain with examples what should the code do.
@@nikoo28 You are right for ["bdddddddddd","bbbbbbbbbbc"] this will not going to pass. Probably new test cases have been added. Thank you for your response. Your tutorials are really helpful.
If you are concerned about having an overall faster solution, C++ should be the preferred language. Even with Java you can leverage some sort of caching and pre-processing of some results to obtain faster solutions. Generally not needed.
c is the actual character…let us say it is character ‘k’ And we do c - ‘a’ What happens internally is both are converted to ascii Small ‘a’ has ascii 97 The character ‘k’ has ascii 107 So when you do c - ‘a’ we get 107-97 = 10 That means freq[10] This represents 11th character as array is 0 based indexing Means we are referring to frequency of 11th character in the English alphabet which is letter ‘k’
Yea…I don’t understand why my channel does not show up in results and suggestions. I have been doing everything possible: video descriptions, links etc.
@@nikoo28 I have found another solution here. Not explained in detail as you have done, but this one has less lines of code. ruclips.net/video/fAJqAnEWq0o/видео.html&ab_channel=ThatIndianCoder
loved your explanation . But 1 thing I would like to correct . The time complexity of method 1 will be O(n k log k ) , where k is the length of the string , n is total strings . This is because sorting a string would take (k log k ) . Any way awesome explanation . thanks
I generally not hit like on youtube videos, but this guy nailed it. Thanks for your community contribution NIkhil.
I was missing ONE idea and it popped in my head when I saw your first method, amazing explanation!
I got really surprised by so a vivid and clear explanation. I appreciate your efforts.
Glad I could help you out 😄
sir you explaination to any algorithm is the best explanation i had ever seen ...only your explanation is enough to solve the problem no need to see the code
Dhanyavad bhaiya, you are the best teacher I have seen on youtube😭
So nice of you
Very clear explanation! Keep up!!! 👍🏻
At the beginning it was difficult to find out how to solve this problem, but with this explanation it make it easy to solve it. Thank.
i'm new to python and this was my solution
def smash(str):
tmp = 1
orda = ord('A')-1
ls = len(str)
for i in range( ls ):
tmp = tmp * (ord(str[i]) - orda)
return tmp
def groop(wordlist):
grope = {}
for word in wordlist:
hashy = smash(word)
if hashy not in grope:
grope[hashy] = []
grope[hashy].append(word)
return [val for val in grope.values()]
if __name__ == '__main__':
# arr = [ 'cat','tea','tan','ate','nat','bat' ]
arr = [ 'eat','cars','tea','scar','a','listen','silent']
print (groop(arr))
this solution worked in codewars but not leetcode. i need to refine the smash function to prevent duplicate hashes
In the sorting way, the time complexity is not O(nlogk) but rather O(n.klogk)
very nice explanation
Hey, I found this video trough the article and thank you for all the work, it really helped me. The solution of method 2 at line 34 has a mistake: "freq++;", you can't ++ an array, so we need to do freq[c - 'a']++ :)
bro, thank you for the video. it was very usefull (like all your videos)
great video and best ever explaination ever
Awesome 👏✊👍
great explanation with animation step by step
That's an amazing explanation! 👏👏
Very well explained the techniques, code and dry-run. Great work Nikhil.
I don't know why, I ran both techniques sorting and frequency but sorting is showing less time than frequency method. sorting => 15ms frequency = 29ms. I believe its random.
@@shaileshsathe9779 I'm not sure but I think it might be because frequency string has to be sorted so it takes even longer to count everything and sort the letters alphabetically
Premium Explanation
🤘🏻
Appreciate your effort !!!
Great video as usual thanks for this! PS its not pronounced vo-i-la but just vo-la, hope this helps!
sir awesome explanation ...................
this there any better way for a frequency string algothrim?
Thank you Nikhil :D
Nice explanation
you are the best
8:14 should be "nat", not sorted string "ant".
Otherwise your tutorials are the best regarding leetcode problems, because you explain with examples what should the code do.
your accent is sweet
This might not pass all test cases, you have to add a delimiter like '#' while concatenating numbers in freq variable.
passes all cases on Leetcode as per the problem constraints. If you have different strings patterns, it might need a little tweaking.
@@nikoo28 You are right for ["bdddddddddd","bbbbbbbbbbc"] this will not going to pass. Probably new test cases have been added.
Thank you for your response. Your tutorials are really helpful.
Best
But why light theme?? I am blind now..
Light is easier for diagrams and animations. Will keep using light theme.
beats 30% java codes, wonder what could be a better solution!
If you are concerned about having an overall faster solution, C++ should be the preferred language.
Even with Java you can leverage some sort of caching and pre-processing of some results to obtain faster solutions. Generally not needed.
@@nikoo28 thanks sir
tried watching but you just explained what the code does and its too confusing for me to undertsand what
for each
freq [c -'a']++;
Does
c is the actual character…let us say it is character ‘k’
And we do c - ‘a’
What happens internally is both are converted to ascii
Small ‘a’ has ascii 97
The character ‘k’ has ascii 107
So when you do c - ‘a’ we get 107-97 = 10
That means freq[10]
This represents 11th character as array is 0 based indexing
Means we are referring to frequency of 11th character in the English alphabet which is letter ‘k’
@@nikoo28 Thanks .
Excellent ... But disheartened to see less subscribers ... ☹️😑🙂
Yea…I don’t understand why my channel does not show up in results and suggestions. I have been doing everything possible: video descriptions, links etc.
@@nikoo28 You can add keywords like Leetcode, Anagram, Interview Prep just like you added for String.Maybe it will work
There's nothing correct about this video. Lol. Indian programmers lulz
did you find some problem in the explanation or the method? Always up for improvement...
@@nikoo28
I have found another solution here.
Not explained in detail as you have done, but this one has less lines of code. ruclips.net/video/fAJqAnEWq0o/видео.html&ab_channel=ThatIndianCoder
@@nikoo28 You are best!