from collections import Counter class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: f = Counter(nums) return [x[0] for x in f.most_common(k)]
@KarthiKarthi-df2mp2 ай бұрын
You have nailed the explanation, its perfect.....but what if the top k is 2 and the last list in an bucket as 5 numbers?
@TeddySmithDev2 ай бұрын
It will store those numbers under bucket[6] within nested list. The nested list gives the ability to add multiple numbers within array and when it iterates backwards it will get those two numbers. If I did not understand your question correct, please comment again and i will look.
@KarthiKarthi-df2mp2 ай бұрын
Thanks for the explanationsl man!....I got it thank you very much....looking for lot more videos with this wonderful explanation.