https://www.hackerrank.com/challenges/equality-in-a-array/problem?isFullScreen=true
Equalize the Array | HackerRank
Delete a minimal number of elements from an array so that all elements of the modified array are equal to one another.
www.hackerrank.com
Given an array of integers, determine the minimum number of elements to delete to leave only elements of equal value.정수 배열이 주어졌을 때, 동일한 값의 요소만 남도록 삭제할 최소 원소 수를 결정합니다.
Example본보기
Delete the elements and leaving . If both twos plus either the or the are deleted, it takes deletions to leave either or . The minimum number of deletions is .원소를 삭제하고 . 만약 두 개의 2와 또는 중 하나가 삭제되면, 남기려면 삭제가 필요합니다. 최소 삭제 횟수는 입니다.
Function Description기능 설명
Complete the equalizeArray function in the editor below.아래 편집기에서 equalizeArray 함수를 완성하세요.
equalizeArray has the following parameter(s):equalizeArray는 다음과 같은 매개변수를 가집니다:
- int arr[n]: an array of integersint arr[n]: 정수 배열입니다
Returns반환
- int: the minimum number of deletions requiredint: 필요한 최소 삭제 횟수
Input Format입력 형식
The first line contains an integer , the number of elements in .
The next line contains space-separated integers .첫 번째 줄은 정수 를 포함하며, 에 속하는 원소 수를 의미합니다. 다음 줄은 공간 분리 정수 를 포함한다.
Constraints제약 조건
Sample Input샘플 입력
STDIN Function
----- --------
5 arr[] size n = 5
3 3 2 1 3 arr = [3, 3, 2, 1, 3]
Sample Output샘플 출력
2
Explanation설명
Delete and to leave . This is minimal. The only other options are to delete elements to get an array of either or .삭제하고 떠나세요. 이 정도는 최소한입니다. 다른 방법은 요소를 삭제하여 또는 의 배열을 만드는 것뿐입니다.
풀이
101개 배열 만들고, 가장 많이 중복되는 숫자의 중복 개수를 찾고,
전체 사이즈에서 빼주어 해결했습니다.

'알고리즘 단련장 > 해커랭크' 카테고리의 다른 글
| [해커랭크] Queen's Attack II (0) | 2025.12.12 |
|---|---|
| [해커랭크] 실버 달성 (0) | 2025.12.10 |
| [해커랭크] Jumping on the Clouds (0) | 2025.12.04 |
| [해커랭크] Repeated String (0) | 2025.12.04 |
| [해커랭크] Non-Divisible Subset (0) | 2025.12.04 |