You are viewing a single comment's thread. Return to all comments →
Similar to your solution but I didn't use the max variable. Instead of that I used Collection class to pull out the key having maximum count.
public static void main(String[] args) { Scanner sc = new Scanner (System.in); int n = sc.nextInt(); HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); for (int i = 0;i < n;i++) { int num = sc.nextInt(); if (map.containsKey(num)) map.put(num, map.get(num) + 1); else map.put(num, 1); } System.out.println(n - Collections.max(map.values())); }
Seems like cookies are disabled on this browser, please enable them to open this website
Equalize the Array
You are viewing a single comment's thread. Return to all comments →
Similar to your solution but I didn't use the max variable. Instead of that I used Collection class to pull out the key having maximum count.