You are viewing a single comment's thread. Return to all comments →
public static List<Integer> cutTheSticks(List<Integer> arr) { // Write your code here List<Integer> result = new ArrayList<>(); while (arr.size() > 0) { result.add(arr.size()); Integer smallest = arr.stream().min(Integer::compareTo).orElse(0); arr = arr.stream() .map(i -> i - smallest) .filter(i -> i > 0) .collect(toList()); } return result; }
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 →