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

  Рет қаралды 9,925

NeetCodeIO

NeetCodeIO

Күн бұрын

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🧑‍💼 LinkedIn: / navdeep-singh-3aaa14161
🐦 Twitter: / neetcode1
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
Problem Link: leetcode.com/problems/least-n...
0:00 - Read the problem
0:22 - Drawing Explanation 1
6:33 - Coding Explanation 1
8:56 - Drawing Explanation 2
13:53 - Coding Explanation 2
leetcode 1481
#neetcode #leetcode #python

Пікірлер: 14
@dumbfailurekms
@dumbfailurekms 4 ай бұрын
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
@barnetthan9391
@barnetthan9391 4 ай бұрын
me too!
@akshayiithyd
@akshayiithyd 4 ай бұрын
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 4 ай бұрын
so impressive, thanks a lot sir
@armandomendivil1117
@armandomendivil1117 4 ай бұрын
I solved it using bucket sort too!!
@poketopa1234
@poketopa1234 3 ай бұрын
Great video, thank you
@kirillzlobin7135
@kirillzlobin7135 4 ай бұрын
Amazing
@skguravana703
@skguravana703 4 ай бұрын
Today I am happy that I have solved this by myself🎉
@Aditya_qwertyu
@Aditya_qwertyu 4 ай бұрын
congrarts
@Moch117
@Moch117 4 ай бұрын
Seemed like a greedy and sorting problem
@marthimallikarjun5427
@marthimallikarjun5427 4 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
Thanks bro! U saved my streak
@Sam-nc6xt
@Sam-nc6xt 4 ай бұрын
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
Largest Divisible Subset - Leetcode 368 - Python
22:57
NeetCodeIO
Рет қаралды 14 М.
#28 Creation of Array in Java
7:29
Telusko
Рет қаралды 125 М.
Пробую самое сладкое вещество во Вселенной
00:41
Must-have gadget for every toilet! 🤩 #gadget
00:27
GiGaZoom
Рет қаралды 12 МЛН
БОЛЬШОЙ ПЕТУШОК #shorts
00:21
Паша Осадчий
Рет қаралды 8 МЛН
Rearrange Array Elements by Sign - Leetcode 2149 - Python
10:25
Height Checker - Leetcode 1051 - Python
8:40
NeetCodeIO
Рет қаралды 7 М.
Find Polygon with the Largest Perimeter - Leetcode 2971 - Python
10:41
Day 9 - Solving LeetCode Problems Until FAANG Hires Me
10:07
Sequential Digits - Leetcode 1291 - Python
15:02
NeetCodeIO
Рет қаралды 12 М.
Find the Town Judge - Leetcode 997 - Python
9:55
NeetCodeIO
Рет қаралды 16 М.
Пробую самое сладкое вещество во Вселенной
00:41