You are viewing a single comment's thread. Return to all comments →
List<Integer> list=new ArrayList<>(); Map<Integer,Long> map= arr.stream().collect(Collectors.groupingBy(Function.identity(),Collectors.counting())); Set<Integer> set=new TreeSet<>(); set=map.keySet(); long sum; int min; while(set.isEmpty()!=true){ min= set.stream().min(Integer::compare).orElse(0); sum = map.values().stream().reduce(0l, (a,b)->a+b); set.remove(min); list.add((int)sum); } return list;
Seems like cookies are disabled on this browser, please enable them to open this website
Cut the sticks
You are viewing a single comment's thread. Return to all comments →
Java8