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
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
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']++ :)
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.
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’
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.
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. ua-cam.com/video/fAJqAnEWq0o/v-deo.html&ab_channel=ThatIndianCoder
I generally not hit like on youtube videos, but this guy nailed it. Thanks for your community contribution NIkhil.
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 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
Hey, you are super underrated, I didn't know about you channel but now I know and will be utilizing it in my preparation.
Dhanyavad bhaiya, you are the best teacher I have seen on youtube😭
So nice of you
You can avoid unnecessary d0eof0 in 2nd solution by putting condition ...if (i != 0) then only append!
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.
Excellent explaination..!! Very clean and clear. I Loved It.💝💝
Premium Explanation
🤘🏻
Very clear explanation! Keep up!!! 👍🏻
In the sorting way, the time complexity is not O(nlogk) but rather O(n.klogk)
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
Thank you, you explained it very well!
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
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)
That's an amazing explanation! 👏👏
great explanation with animation step by step
great video and best ever explaination ever
very nice explanation
Appreciate your effort !!!
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.
If I use sorting logic will be my solution wrong?
I am facing difficulty in understanding the HasMap and Frequency Concept.
Great video as usual thanks for this! PS its not pronounced vo-i-la but just vo-la, hope this helps!
Awesome 👏✊👍
Thank you Nikhil :D
sir awesome explanation ...................
you are the best
which is has more time complexity ?
this there any better way for a frequency string algothrim?
We need to write getfrequency string string method also sep?
obviously
Nice explanation
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.
you should have initialized char as something like char_count, initializing it with "c" makes the program confusing.
char 'c' is a very standard practice in competitive programming.
sirr !
But why light theme?? I am blind now..
Light is easier for diagrams and animations. Will keep using light theme.
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 .
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
Best
your accent is sweet
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. ua-cam.com/video/fAJqAnEWq0o/v-deo.html&ab_channel=ThatIndianCoder
@@nikoo28 You are best!