• + 0 comments

    java 8 :

        public static List<Integer> cutTheSticks(List<Integer> arr) {
        int count=0;
        List<Integer> res = new ArrayList<>();
        
        while(arr.size>0){
            int sm = Collections.min(arr);
            for(int j = 0 ; j<arr.size(); j++){
                arr.set(j, arr.get(j)-sm);
                count++;
                }
                res.add(count);
                count = 0;
                arr = arr.stream().filter(x -> x>0).collect(Collectors.toList());   
        }
        return res;
        }