Least Number of Unique Integers after K Removal - Leetcode 1481 - Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024

ความคิดเห็น • 14

  • @dumbfailurekms
    @dumbfailurekms 8 หลายเดือนก่อน +11

    I used the bucket sort approach you taught us in Top K frequent elements. I'm going to analyze the time complexity of mine then watch your video but thanks for being such a great teacher. I learned (and will continue to learn) so much from you. I used to be so clueless. Thank youu

  • @akshayiithyd
    @akshayiithyd 8 หลายเดือนก่อน +2

    I love the fact that even if I am able to solve the question, I almost always get something useful from Neetcode's solution, somedays It is the optimized approach, and on the other it is better code quality.

  • @KhyatiSatija
    @KhyatiSatija 8 หลายเดือนก่อน +1

    so impressive, thanks a lot sir

  • @poketopa1234
    @poketopa1234 6 หลายเดือนก่อน

    Great video, thank you

  • @armandomendivil1117
    @armandomendivil1117 8 หลายเดือนก่อน +1

    I solved it using bucket sort too!!

  • @skguravana703
    @skguravana703 8 หลายเดือนก่อน

    Today I am happy that I have solved this by myself🎉

  • @kirillzlobin7135
    @kirillzlobin7135 8 หลายเดือนก่อน

    Amazing

  • @marthimallikarjun5427
    @marthimallikarjun5427 8 หลายเดือนก่อน +1

    Can someone explain the logical mistake in my code
    class Solution:
    def findLeastNumOfUniqueInts(self, arr: List[int], k: int) -> int:
    count = Counter(arr)
    arr.sort(key=lambda x: count[x], reverse=True)
    n = len(arr)
    return len(set(arr[:n - k]))
    please...!!

    • @jts3077
      @jts3077 8 หลายเดือนก่อน +1

      add arr.sort() before sorting by the count. This is because even though you sorted by count, the numbers with the same count can appear in any order. For instance, [1,1,2,2] could get sorted to [1,2,1,2] because 1 and 2 have the same count.

    • @marthimallikarjun5427
      @marthimallikarjun5427 8 หลายเดือนก่อน +1

      Thanks bro! U saved my streak

    • @Sam-nc6xt
      @Sam-nc6xt 8 หลายเดือนก่อน

      You could also do this -
      arr.sort(key=lambda x: (count[x], x), reverse=True)
      It will first sort by freq and then by value which will fix the order as well

  • @Moch117
    @Moch117 8 หลายเดือนก่อน +1

    Seemed like a greedy and sorting problem