Maximum Frequency Stack - Leetcode 895 - Python

  Рет қаралды 28,449

NeetCode

NeetCode

Күн бұрын

Пікірлер: 56
@coder4937
@coder4937 2 жыл бұрын
When you ever stuck in a problem just throw a hashmap 😄
@tanmaymishra1109
@tanmaymishra1109 2 жыл бұрын
Agree😁
@rahmaniastrid
@rahmaniastrid 2 жыл бұрын
hey neetcode, just want to let you know that I got an offer from a FAANG company after months of rigorously going through problems and watching your vids to clear up confusion when I got stuck. Personally I found that your explanations are the best, you don't just talk code but you talk about the underlying concepts (and explaining them with clear drawings are a HUGE BONUS) which most of other youtubers kind of skip. I can't thank you enough, keep up the good work! Your work will help many people I am so sure of it. I still have another set of interview with another FAANG company, hopefully I'll whichever company I'll end up with will be the best choice. So you bet I will still grind your vids for the foreseeable future (and onwards of course). Cheers!
@AmanNidhi
@AmanNidhi 2 жыл бұрын
what was your language of choice
@Pegasus02Kr
@Pegasus02Kr 2 жыл бұрын
Took about 1.5 months to walkthrough all your Coding Interview Solutions playlist. I really appreciate for all your works!
@SkyeTian
@SkyeTian 2 жыл бұрын
Simplified a little bit : import collections class FreqStack: def __init__(self): self.count = {} self.groups = collections.defaultdict(list) def push(self, val): self.count[val] = self.count.get(val, 0) + 1 self.groups[self.count[val]].append(val) def pop(self): result = self.groups[max(self.groups.keys())].pop() self.count[result] -= 1 if self.groups[max(self.groups.keys())] == []: self.groups.pop(max(self.groups.keys())) return result
@venkatasriharsha4227
@venkatasriharsha4227 2 жыл бұрын
There are no words to tell how beautifully u put these videos so simple. Finally got a decent product job. I would love to watch neetcode even if I grow older ❤. Keep posting the videos
@priyanshupriyam174
@priyanshupriyam174 3 ай бұрын
Thanks Neetcode for making this problem simpler for me!
@suhailf5014
@suhailf5014 2 жыл бұрын
You make me fall in love with Coding! Many many thanks :) Keep up the good work please ;p
@victoriac7257
@victoriac7257 2 жыл бұрын
I always feel released when I got stuck in a problem but found out that you have posted a video solution on it. Thanks NeetCode!! Keep going!!!!
@consistentthoughts826
@consistentthoughts826 2 жыл бұрын
This one idea of maintaining stack ( stack = valcnt : [1,2,3] ) saved me. Thanks great solution
@ChandraShekhar-by3cd
@ChandraShekhar-by3cd 2 жыл бұрын
Thanks a lot for such a great explanation. Love from India ♥
@vdyb745
@vdyb745 2 жыл бұрын
Dude !!! You are a leetcode GOD !!!! Fantastic visual explanation and code. Thanks !
@KishoreKumar-ve1xb
@KishoreKumar-ve1xb 2 жыл бұрын
If I get a job in the future..... It's 100 percent because of NeetCode! Thank you So much and Congratulations for 100k subscribers You deserve it because you have the best video explanations on the entire internet....btw this is probably the Easiest Hard problem I've ever seen
@simonbabatunde4333
@simonbabatunde4333 2 жыл бұрын
"Easiest hard problem" because it's been solved already. You can only say that if you sit at it to implement yourself.
@KishoreKumar-ve1xb
@KishoreKumar-ve1xb 2 жыл бұрын
@@simonbabatunde4333 I solved it before the video dropped because it was a daily challenge problem for March 19th. I can see why it can look complicated ...... the first thing that comes to mind is to use heaps.... but the simplest way turned out to be the optimal solution. I'm pretty sure I've seen a similar problem before.
@KishoreKumar-ve1xb
@KishoreKumar-ve1xb 2 жыл бұрын
I found the similar problem from my spreadsheet. 347. Top K Frequent Elements.
@somakkamos
@somakkamos 2 жыл бұрын
neetcode is like the rachel maddow of all tech youtubers...... best explainer everrrrrrr...
@hanklin4633
@hanklin4633 2 жыл бұрын
I like this one where you focus on the thought process to find the solution
@masternobody1896
@masternobody1896 2 жыл бұрын
me as an unemployee year 3 day 25. amazing video. i wonder how long it will take a job at fang
@NeetCode
@NeetCode 2 жыл бұрын
i know you'll make it buddy 🥲
@Colls-m8i
@Colls-m8i 2 жыл бұрын
@@NeetCode how long did it take you?…starting this interview questions journey myself…feels dreadful. What do you think of first whenever you face a problem that looks impossible to solve? What one thing do you always do in yr thinking approach to these questions?
@heathens2867
@heathens2867 2 жыл бұрын
@@Colls-m8i if you'll practice coding regularly just 3 hours each day for like 6-7 months. You gonna ace normal startup interviews and if you'll continue so for next 9-12 months. You'll ace good product based company easily. Not sure about Google but definitely a good company. I just got a job in Adobe.
@vadimkokielov2173
@vadimkokielov2173 2 жыл бұрын
I don't think you need to keep track of the maximum. A frequency can only ever be incremented (increased by one). Thus the maximum frequency can only ever rise by one. Thus it is enough to keep an array, indexed by frequency-1. Its size is then the maximum frequency.
@Dezdichado1000
@Dezdichado1000 2 жыл бұрын
there is something between this problem and a Young Tableux now that the final structure is revealed to be this stack of lists of decreasing heights.
@VarunMittal-viralmutant
@VarunMittal-viralmutant 2 жыл бұрын
My implementation, I find it one more intuitive :) --------------------------------------------------------- class FreqStack: def __init__(self): self.c = count(0) self.pq = [] self.freq = defaultdict(int) def push(self, data): self.freq[data] += 1 heapq.heappush(self.pq, (-self.freq[data], -next(self.c), data)) def pop(self): while self.pq: _, _, d = heapq.heappop(self.pq) self.freq[d] -= 1 return d raise KeyError("pop from empty cache")
@hanklin4633
@hanklin4633 2 жыл бұрын
Man how do you keep up uploading these even while working at google. But good job keep up the good work, I'm still trying one day I may also pass the google interview.
@ChenAubrey
@ChenAubrey 2 жыл бұрын
Wow, Now you're in the Daily Challenge. Thank you for great video
@janardannn
@janardannn 5 ай бұрын
wow thats a really creative solution
@nw3052
@nw3052 Жыл бұрын
Perfect explanation
@saijayavinothtvs2588
@saijayavinothtvs2588 2 жыл бұрын
Heap will work, just keep the heap index of a valand update its freq and do top to bottom and bottom to top...
@narayanavasisthakandarpa96
@narayanavasisthakandarpa96 2 жыл бұрын
Very good solution
@kousthubhtadanki1237
@kousthubhtadanki1237 2 жыл бұрын
superb explanation
@ShivangiSingh-wc3gk
@ShivangiSingh-wc3gk 2 жыл бұрын
Yes, thought of the heap solution n(log n) -> O(n^2) worst case :(
@akashverma5756
@akashverma5756 8 ай бұрын
HashMap is jack of all trades.
@weishin
@weishin 2 жыл бұрын
Can you take a look at some of the questions that Meta gives on their career pages?
@jchakrab
@jchakrab 2 жыл бұрын
I need a confirmation from you on height vs depth of a binary tree...for the height the base condition is "if not root: return -1" and for depth it is "return 0" right ?? when you search on google for height of a binary tree you will see both cases as valid answer...i am a bit confused could you please answer this. Height of null tree is -1, height of a single node is 0, right ?
@TheElementFive
@TheElementFive 2 жыл бұрын
Enjoyable problem and nice explanation!
@rjarora
@rjarora 6 ай бұрын
You are awesome man!
@MrSugar51
@MrSugar51 2 жыл бұрын
Hello NeetCode, Thank you for your great work. I’m just curious about what software you are using for drawing explanations and screen recording because I need to make the same kind of videos for my friends.
@NeetCode
@NeetCode 2 жыл бұрын
I use Paint3D with a mouse, and Streamlabs OBS for screen recording.
@MrSugar51
@MrSugar51 2 жыл бұрын
@@NeetCode thank you very much. The streaming software is what I’ve never come up is. I appreciate it. Just fyi I was surprised that you’re using Windows instead of Mac
@fia6559
@fia6559 2 жыл бұрын
What do you think about AlphaCode?
@pranavsharma7479
@pranavsharma7479 2 жыл бұрын
bro also share tips to prep for faang from where to do word problems to clear first round
@vdyb745
@vdyb745 2 жыл бұрын
What shortcut did you use to change stack to stacks ? I am able to do the multi-cursor operation in vscode but not in stackoverflow editor
@ParthShirawala
@ParthShirawala 2 жыл бұрын
Thanks for the help mate
@mdilyaspasha2736
@mdilyaspasha2736 2 жыл бұрын
Sir Please make videos java problems
@Douglasfaparanhos
@Douglasfaparanhos 2 жыл бұрын
Very smart 👏👏
@marshallshao
@marshallshao 2 жыл бұрын
Hi man, I really like your video.. Unfortunately, I got rejection letter from Google yesterday.. Now I am really frustrating. :( Even I solved the problem during interview..
@marshallshao
@marshallshao 2 жыл бұрын
I just wanted to say THANKS!
@nguessaneric9830
@nguessaneric9830 2 жыл бұрын
Was it the phone interview?
@marshallshao
@marshallshao 2 жыл бұрын
@@nguessaneric9830 No, The first round of coding interview
@vantran321
@vantran321 2 жыл бұрын
Just copped that Patreon 10 pack fam. It's peanuts next to your Google salary but enjoy a coffee on me
@NeetCode
@NeetCode 2 жыл бұрын
Thank you so much!!! I really appreciate it!
@somith16
@somith16 2 жыл бұрын
What projects did u put while applying for job interview at google
@ivanwen8335
@ivanwen8335 2 жыл бұрын
OHHHHHH, WOWWWWWWW
Next Greater Element I - Leetcode 496 - Python
14:53
NeetCode
Рет қаралды 79 М.
Open the Lock - Leetcode 752 - Python
14:22
NeetCode
Рет қаралды 41 М.
JISOO - ‘꽃(FLOWER)’ M/V
3:05
BLACKPINK
Рет қаралды 137 МЛН
UFC 287 : Перейра VS Адесанья 2
6:02
Setanta Sports UFC
Рет қаралды 486 М.
Counter-Strike 2 - Новый кс. Cтарый я
13:10
Marmok
Рет қаралды 2,8 МЛН
8 Data Structures Every Programmer Should Know
17:09
ForrestKnight
Рет қаралды 174 М.
Maximum Frequency Stack | Live Coding with Explanation | Leetcode - 895
14:43
Coding Interview Problem: Largest Rectangle in a Histogram
16:18
Jackson Gabbard
Рет қаралды 309 М.
Shortest Bridge - Leetcode 934 - Python
14:51
NeetCode
Рет қаралды 39 М.
I Solved 100 LeetCode Problems
13:11
Green Code
Рет қаралды 245 М.
I Solved 1583 Leetcode Questions  Here's What I Learned
20:37
ThePrimeTime
Рет қаралды 735 М.
Remove K Digits - Leetcode 402 - Python
14:36
NeetCode
Рет қаралды 64 М.
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 281 М.