Thank you broski I had the right idea and was working on it but the explanation really helped me out. However, one small suggestion maybe include the previous problem in the description since I did that one first and it helped out when moving onto the second. Great video!!!
หลายเดือนก่อน
first daily medium I solved by myself, all thanks to your channel
in this problem no, but in othere problems if u need to make alot of del, insert and keep maintaining a sorted array heap would be much better in time complixty
class Solution: def minimumPushes(self, word: str) -> int: d=dict(Counter(word)) m=[] for i,j in d.items(): m.append((j,i)) m.sort(reverse=True) print(m) c=2 s=0 a=0 for p,q in m: if c9 and c=18 and c=26: s+=(p*4) c+=1 return s we could solve the problem with this approach as well @NeetCodeIO
@@guy_cod yeah like for an ideal case it is O(NlogN)... But we are sorting a constant space list ie, 26 so it takes constant time.. So overall just O(N)
Sometimes, I feel like I am God before watching the video,I was able to come with a solution, but I came here to see his approach. the approach is same❤
How about this? class Solution: def minimumPushes(self, word: str) -> int: c=list(Counter(word).items()) c.sort(key=lambda x:x[1],reverse=True) count=0 k=1 for i,j in enumerate(c,start=1): count+= j[1]*k if i%8==0: k+=1 return count
First comment pin me bro📌
Fine but you better not edit it
😂😂 @@NeetCodeIO
That "back in my day" hits different since we're not even that old to use this phrase.
im 21 and this also applies to me
I just saw the problem was II then solved first one and then came straight to Neetcode for explanation
The problem description is too long
These interns need to have their writing skills vetted 😂
reading the problem makes you feel like a nightmare but we actually its not ... well hurrah solved it w/o seeing ur video or intuition
Done on my own
Damn Ascii values to solve this problem was genius!!
i think you should start a codeforces series leetcode is getting easy
Thank you broski I had the right idea and was working on it but the explanation really helped me out. However, one small suggestion maybe include the previous problem in the description since I did that one first and it helped out when moving onto the second. Great video!!!
first daily medium I solved by myself, all thanks to your channel
Solved it on my own. A bit easy problem.
for counting you can use a hash map with characters as keys and then get the sorted array of values by using list(dict.values()) and then sort
really loved the explanation. thank you neetcode!
I wanted to know is there any improvement or advantages of using heap way rather than just sorting?
in this problem no, but in othere problems if u need to make alot of del, insert and keep maintaining a sorted array heap would be much better in time complixty
Could you please explain this problem - Time Taken to Mark All Nodes (LeetCode - 3241). Please...
Thanks a Lot G!
class Solution:
def minimumPushes(self, word: str) -> int:
d=dict(Counter(word))
m=[]
for i,j in d.items():
m.append((j,i))
m.sort(reverse=True)
print(m)
c=2
s=0
a=0
for p,q in m:
if c9 and c=18 and c=26:
s+=(p*4)
c+=1
return s
we could solve the problem with this approach as well @NeetCodeIO
what the hell
@@apodikoglou Means ?
Thank you for the daily
super clever. !
broo isn't the time complexity just O(n)?
@@7akon yeah he said O(NlogN)..... But its just O(N)
sorting is O(NlogN)
@@guy_cod yeah like for an ideal case it is O(NlogN)... But we are sorting a constant space list ie, 26 so it takes constant time.. So overall just O(N)
@@krupakarreddy1758 thank you for the explanation
You just understand the examples for this question, you will find the approach
Nice
class Solution:
def minimumPushes(self, word: str) -> int:
MAX_BUTTONS = 8
count_keys = 0
pushes = 0
for key in Counter(word).most_common():
pushes += key[1] * (1 + count_keys // MAX_BUTTONS)
count_keys += 1
return pushes
Sometimes, I feel like I am God before watching the video,I was able to come with a solution, but I came here to see his approach. the approach is same❤
How about this?
class Solution:
def minimumPushes(self, word: str) -> int:
c=list(Counter(word).items())
c.sort(key=lambda x:x[1],reverse=True)
count=0
k=1
for i,j in enumerate(c,start=1):
count+= j[1]*k
if i%8==0:
k+=1
return count
return sum(c*(1+i//8)for i,c in enumerate(sorted(Counter(w).values(),reverse=1)))
This sol is from larry.
The rent is too damn high!