Top K Frequent Elements - Leetcode 347 - Heaps (Python)

Поділитися
Вставка
  • Опубліковано 20 жов 2024
  • Master Data Structures & Algorithms for FREE at AlgoMap.io/
    Code solutions in Python, Java, C++ and JS for this can be found at my GitHub repo here: github.com/gah...
    Complete DSA Pathway Zero to Hero: • Data Structures & Algo...
    Please check my playlists for free DSA problem solutions:
    • Fundamental DSA Theory
    • Array & String Questions
    • 2 Pointers Questions
    • Sliding Window Questions
    • Binary Search Questions
    • Stack Questions
    • Linked List Questions
    • Tree Questions
    • Heap Questions
    • Recursive Backtracking...
    • Graph Questions
    • Dynamic Programming (D...
    My Data Science & ML UA-cam Playlist: • Greg's Path to Become ...
    Learn Python and Data Science FASTER at mlnow.ai :)
    Support the content: / @greghogg
    Follow me on Instagram: / greghogg5
    Connect with me on LinkedIn: / greghogg
    Follow me on TikTok: / greghogg5
    Coursera Plus: imp.i384100.ne...
    My Favorite Courses:
    Data Structures & Algorithms:
    UCalifornia San Diego DSA: imp.i384100.ne...
    Stanford Algorithms: imp.i384100.ne...
    Python Data Structures: imp.i384100.ne...
    Meta Coding Interview Prep: imp.i384100.ne...
    Python:
    UMichigan Python for Everybody: imp.i384100.ne...
    Python Mastery from MLNOW.ai: mlnow.ai/cours...
    Google IT Automation w/ Python: imp.i384100.ne...
    Web Dev / Full Stack:
    Meta Front-End Developer: imp.i384100.ne...
    IBM Full Stack Developer: imp.i384100.ne...
    Meta Back-End Developer: imp.i384100.ne...
    John Hopkins HTML, CSS & JS: imp.i384100.ne...
    IBM DevOps: imp.i384100.ne...
    Cloud Development:
    AWS Fundamentals: imp.i384100.ne...
    GCP Cloud Engineer: imp.i384100.ne...
    Microsoft Azure Fundamentals: imp.i384100.ne...
    Game Development:
    Michigan State Unity Development: imp.i384100.ne...
    UColorado C++ for Unreal Engine: www.coursera.o...
    SQL & Data Science:
    SQL by MLNOW.ai: mlnow.ai/cours...
    Python for Data Science by MLNOW.ai: mlnow.ai/cours...
    Google Data Analytics: imp.i384100.ne...
    IBM Data Science: imp.i384100.ne...
    IBM Data Engineer: imp.i384100.ne...
    Machine Learning & AI:
    ML Mastery at MLNOW.ai: mlnow.ai/cours...
    ML w/ Andrew Ng: www.coursera.o...
    Deep Learning w/ Andrew Ng: imp.i384100.ne...

КОМЕНТАРІ • 22

  • @GregHogg
    @GregHogg  2 місяці тому +1

    Master Data Structures & Algorithms For FREE at AlgoMap.io!

  • @christianjt7018
    @christianjt7018 2 місяці тому +1

    The second solution is very creative, thanks for sharing!

    • @GregHogg
      @GregHogg  2 місяці тому

      I love these heap questions, there's some really interesting solutions

  • @rahuldwivedi4758
    @rahuldwivedi4758 9 місяців тому

    Great work. But if you switch context in the middle, please make sure to complete the context. At 4:32 you were talking about max_heap and in that process it seemed you were explaining the time complexity would be O(Nlogk) but it actually was for min_heap.

    • @jiasubaowenke
      @jiasubaowenke 2 місяці тому

      Hi, could you please explain why it's O(nlogk) instead of O(klogn)? I don't know why, thank you!

  • @jiasubaowenke
    @jiasubaowenke 2 місяці тому

    Thank you so much! I have a question that why don't we just use couter.most_common in the heap solution, is it slower than the heap sort?

  • @Flybot20
    @Flybot20 10 місяців тому +1

    Good work. Keep going 👍🏼

  • @samspeaks-hk1vp
    @samspeaks-hk1vp 21 день тому

    please help , how come the second solution is not o(n2)

  • @LearningWorldChatGPT
    @LearningWorldChatGPT 10 місяців тому +1

    Fantastic!
    Thank you for that !

    • @GregHogg
      @GregHogg  10 місяців тому +1

      Very welcome :)

  • @fadygamilmahrousmasoud5863
    @fadygamilmahrousmasoud5863 Місяць тому +1

    This 2nd solution is briliant

    • @GregHogg
      @GregHogg  Місяць тому

      It's really cool

  • @n.h.son1902
    @n.h.son1902 4 місяці тому

    2:12, wait, it should've been O(klogn) if we only consider the work of heap

  • @samspeaks-hk1vp
    @samspeaks-hk1vp 2 місяці тому

    how its o(n) ?we have inner loop

    • @guinea_horn
      @guinea_horn Місяць тому

      Because there isn't an inner loop?

    • @samspeaks-hk1vp
      @samspeaks-hk1vp 21 день тому

      @@guinea_horn second solution from line 15 to 19 should not it be o(n2) ?

    • @guinea_horn
      @guinea_horn 21 день тому

      ​@@samspeaks-hk1vpno, and I'm not sure why you think it is. Unless by n2 you mean 2*n rather than n^2, because we do have two iterations over n items but not an n^2 loop. 2*n reduces to O(n) in typical big o notation

  • @richardpro8927
    @richardpro8927 9 місяців тому

    We need more

  • @cmarquay
    @cmarquay 10 місяців тому +1

    heappy heap

    • @GregHogg
      @GregHogg  10 місяців тому +2

      Heap it up

  • @rattlik1
    @rattlik1 Місяць тому

    most_common?