You are viewing a single comment's thread. Return to all comments →
java 8
public static int equalizeArray(List arr) { int max = 0; // Write your code here
HashMap<Integer, Integer> map = new HashMap<>(); for (int el : arr) { if (map.containsKey(el)) { map.put(el, map.get(el) + 1); } else { map.put(el, 1); } } Set<Integer> keys = map.keySet(); for (int key : keys) { if (map.get(key) > max) { max = map.get(key); } } return arr.size() - max; }
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 →
java 8
public static int equalizeArray(List arr) { int max = 0; // Write your code here