You are viewing a single comment's thread. Return to all 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; }
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 →