TOP K FREQUENT WORDS| LEETCODE 692 | PYTHON CUSTOM HEAP SOLUTION

  Рет қаралды 3,690

Cracking FAANG

Cracking FAANG

Күн бұрын

Пікірлер: 10
@2sourcerer
@2sourcerer Ай бұрын
You can use a tuple instead of HeapItem. Tuple is set as (-count, word). Tuple comparison is resolved on the first element. If first element is equal, then it'll starts to compare the second element, and it happens that it's a mean heap so it's already in lexicographical order.
@seant11
@seant11 6 ай бұрын
Can you explain why in your __lt__ the comparison is self.word > to_compare.word? My assumption is that if you're trying to compare if the current word is lexicographically smaller than the "to_compare" word then it would be self.word < to_compare.word?
@keithang9335
@keithang9335 5 ай бұрын
think about it this way: for 2 strings a and b, a>b if a comes after b in the dictionary. e.g “leetcode” > “idiom” # True you want the 0th element of your min heap to be the one with smallest count and shows up last in the dictionary, so you want (self.count==other.count and self.word > other.word) or (self.count < other.count)
@pranjalgupta6995
@pranjalgupta6995 13 күн бұрын
I think its because we are reversing the result at the end.
@satwiktatikonda764
@satwiktatikonda764 11 ай бұрын
you channel is very underrated
@crackfaang
@crackfaang 11 ай бұрын
I agree haha
@prodbyCheez
@prodbyCheez 5 ай бұрын
Is the to_compare the item that is already on the heap? Also is __lt__ called when you when you first call HeapItem(word, count)?
@kamila5207
@kamila5207 8 ай бұрын
so beautiful solution!! thank you for explaining
@bigboyshassen59
@bigboyshassen59 5 ай бұрын
`return list(reversed(res))`
SUBARRAY SUM EQUALS K | LEETCODE 560 | PYTHON SOLUTION
16:32
Cracking FAANG
Рет қаралды 6 М.
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
DOT PRODUCT OF TWO SPARSE VECTORS - 3 SOLUTIONS EXPLAINED [PYTHON]
31:06
Top K Frequent Elements - Bucket Sort - Leetcode 347 - Python
13:13
Learn Python OOP in under 20 Minutes
18:32
Indently
Рет қаралды 180 М.
Find the Safest Path in a Grid - Leetcode 2812 - Python
26:40
NeetCodeIO
Рет қаралды 15 М.
MAXIMUM SWAP | LEETCODE 670 | PYTHON SOLUTION
15:12
Cracking FAANG
Рет қаралды 7 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 155 М.
Minimum Time Difference - Leetcode 539 - Python
21:43
NeetCodeIO
Рет қаралды 9 М.
Enceinte et en Bazard: Les Chroniques du Nettoyage ! 🚽✨
00:21
Two More French
Рет қаралды 42 МЛН