-
Notifications
You must be signed in to change notification settings - Fork 694
/
Copy pathSolution.java
38 lines (30 loc) · 1.18 KB
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//Problem: https://www.hackerrank.com/challenges/equality-in-a-array
//Java 8
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int itemsToDelete = 0;
int highestFrequency = 1;
HashMap<Integer, Integer> numberFrequency = new HashMap<>();
for(int i = 0; i < n; i++)
{
int curr = input.nextInt();
if(numberFrequency.get(curr) == null)
{
numberFrequency.put(curr, 1);
}
else
{
int newFrequency = numberFrequency.get(curr) + 1;
numberFrequency.put(curr, newFrequency);
highestFrequency = (newFrequency > highestFrequency) ? newFrequency : highestFrequency;
}
}
itemsToDelete = n - highestFrequency;
System.out.println(itemsToDelete);
}
}