Maximum Frequency Stack - Leetcode 895 - Python

Поделиться
HTML-код
  • Опубликовано: 29 ноя 2024

Комментарии • 56

  • @coder4937
    @coder4937 2 года назад +47

    When you ever stuck in a problem just throw a hashmap 😄

  • @rahmaniastrid
    @rahmaniastrid 2 года назад +37

    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 года назад +4

    Took about 1.5 months to walkthrough all your Coding Interview Solutions playlist. I really appreciate for all your works!

  • @SkyeTian
    @SkyeTian 2 года назад +1

    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 года назад +1

    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

  • @suhailf5014
    @suhailf5014 2 года назад +5

    You make me fall in love with Coding!
    Many many thanks :)
    Keep up the good work please ;p

  • @priyanshupriyam174
    @priyanshupriyam174 3 месяца назад

    Thanks Neetcode for making this problem simpler for me!

  • @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!!!!

  • @KishoreKumar-ve1xb
    @KishoreKumar-ve1xb 2 года назад +15

    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 года назад +4

      "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.

  • @masternobody1896
    @masternobody1896 2 года назад +8

    me as an unemployee year 3 day 25. amazing video. i wonder how long it will take a job at fang

    • @NeetCode
      @NeetCode  2 года назад +6

      i know you'll make it buddy 🥲

    • @Colls-m8i
      @Colls-m8i 2 года назад +1

      @@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 года назад +4

      @@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.

  • @consistentthoughts826
    @consistentthoughts826 2 года назад

    This one idea of maintaining stack ( stack = valcnt : [1,2,3] ) saved me. Thanks great solution

  • @hanklin4633
    @hanklin4633 2 года назад +5

    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.

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd 2 года назад +2

    Thanks a lot for such a great explanation. Love from India ♥

  • @somakkamos
    @somakkamos 2 года назад

    neetcode is like the rachel maddow of all tech youtubers...... best explainer everrrrrrr...

  • @vdyb745
    @vdyb745 2 года назад

    Dude !!! You are a leetcode GOD !!!! Fantastic visual explanation and code. Thanks !

  • @Dezdichado1000
    @Dezdichado1000 2 года назад +1

    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.

  • @hanklin4633
    @hanklin4633 2 года назад

    I like this one where you focus on the thought process to find the solution

  • @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.

  • @ChenAubrey
    @ChenAubrey 2 года назад

    Wow, Now you're in the Daily Challenge. Thank you for great video

  • @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")

  • @janardannn
    @janardannn 5 месяцев назад

    wow thats a really creative solution

  • @akashverma5756
    @akashverma5756 8 месяцев назад

    HashMap is jack of all trades.

  • @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...

  • @weishin
    @weishin 2 года назад

    Can you take a look at some of the questions that Meta gives on their career pages?

  • @MrSugar51
    @MrSugar51 2 года назад +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 года назад +3

      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

  • @ShivangiSingh-wc3gk
    @ShivangiSingh-wc3gk 2 года назад

    Yes, thought of the heap solution n(log n) -> O(n^2) worst case :(

  • @TheElementFive
    @TheElementFive 2 года назад

    Enjoyable problem and nice explanation!

  • @kousthubhtadanki1237
    @kousthubhtadanki1237 2 года назад

    superb explanation

  • @nw3052
    @nw3052 Год назад

    Perfect explanation

  • @narayanavasisthakandarpa96
    @narayanavasisthakandarpa96 2 года назад

    Very good solution

  • @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

  • @rjarora
    @rjarora 6 месяцев назад

    You are awesome man!

  • @fia6559
    @fia6559 2 года назад

    What do you think about AlphaCode?

  • @vantran321
    @vantran321 2 года назад +1

    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!

  • @ParthShirawala
    @ParthShirawala 2 года назад

    Thanks for the help mate

  • @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 ?

  • @mdilyaspasha2736
    @mdilyaspasha2736 2 года назад

    Sir Please make videos java problems

  • @marshallshao
    @marshallshao 2 года назад +1

    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

  • @Douglasfaparanhos
    @Douglasfaparanhos 2 года назад

    Very smart 👏👏

  • @somith16
    @somith16 2 года назад

    What projects did u put while applying for job interview at google

  • @ivanwen8335
    @ivanwen8335 2 года назад

    OHHHHHH, WOWWWWWWW