You are viewing a single comment's thread. Return to all comments →
Java 15 Solution
public static int equalizeArray(List<Integer> arr) { HashMap<Integer,Integer> map=new HashMap<>(); for(Integer element:arr){ if(!map.containsKey(element)){ map.put(element,1); }else{ map.put(element,map.get(element)+1); } } Integer maxValue = Collections.max(map.values()); int result=0; int countMax=0; for(Integer value:map.values()){ if(value<maxValue || (value==maxValue && countMax>=1) ){ result+=value; }if(value==maxValue){ countMax+=1; } } return result; }
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 15 Solution