function solution(k, tangerine) {
let tangerineKindCountObj = {};
tangerine.forEach((el) => {
tangerineKindCountObj[el] = tangerineKindCountObj[el] + 1 || 1;
});
let tangerineCountList = Object.values(tangerineKindCountObj);
tangerineCountList.sort((a, b) => b - a);
let cnt = 0;
for (tangerineCount of tangerineCountList) {
if (k <= 0) break;
k -= tangerineCount;
cnt += 1;
}
return cnt;
}
'PS > Programmers' 카테고리의 다른 글
Programmers / Level 2 / [3차] 압축 / JS (0) | 2023.01.25 |
---|---|
Programmers / Level 0 / 캐릭터의 좌표 / JS (0) | 2023.01.24 |
Programmers / Level 3 / 줄 서는 방법 / JS (1) | 2023.01.21 |
Programmers / Level 2 / 2 x n 타일링 / JS (0) | 2023.01.19 |