• + 0 comments
    public static List<Integer> cutTheSticks(List<Integer> arr) {
            arr = arr.stream().sorted().collect(Collectors.toList());
            List<Integer> res = new ArrayList<>();
            while(arr.size() > 0) {
                res.add(arr.size());
                final int shortest = arr.get(0);
                while (!arr.isEmpty() && arr.get(0) == shortest)
                    arr.remove(0);
                arr = arr.stream().map(v -> v - shortest).collect(Collectors.toList());
            }
            return res;
        }