You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This discussion was converted from issue #94 on September 15, 2026 11:07.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/least-number-of-unique-integers-after-k-removals
Problem Summary
배열의 수들을 k개 삭제했을 때 unique한 수의 최소 개수를 구하는 문제.
Solution
그리디로 풀면 된다. 갯수가 적은 수부터 삭제하면 unique한 수를 최소한으로 줄일 수 있다.
map으로 개수를 세고 개수를 기준으로 정렬한 뒤 앞에서부터 제거하면 된다.
O(n)
에디토리얼 보니 O(n)으로도 되는데 정렬하지 않고 나온 개수를 다시 맵에 넣는 방식으로 하면 O(n)이 가능하다. (Counting Sort)
나온 개수를 맵에 넣은 뒤 1부터 체크해서 차례로 제거하면 된다.
Source Code
O(n log n)
O(n)
All reactions