We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
JAVA
There are some solutions using streams, but maybe it will be more readable for somebody:
publicstaticintequalizeArray(List<Integer>arr){//create a map to be able to count occurancesHashMap<Integer,Integer>arrMap=newHashMap<>();for(intnum:arr){if(arrMap.containsKey(num)){arrMap.put(num,arrMap.get(num)+1);}else{arrMap.put(num,1);}}intmax=0;for(intvalueOfArrMap:arrMap.values()){if(valueOfArrMap>=max)max=valueOfArrMap;}returnarr.size()-max;
Cookie support is required to access HackerRank
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 There are some solutions using streams, but maybe it will be more readable for somebody: