You are viewing a single comment's thread. Return to all comments →
public static List<Integer> cutTheSticks(List<Integer> arr) { List<Integer> result = new ArrayList<>(); result.add((int)arr.stream().filter(s -> s!=0).count()); while(arr.stream().filter(a -> a!=0).count() != 0) { int minval = arr.stream().mapToInt(s -> s).filter(s -> s != 0).min().getAsInt(); arr = arr.stream().map(val -> val != 0 ? val-minval : val).collect(Collectors.toList()); int cnt = (int)arr.stream().filter(s -> s!=0).count(); if(cnt != 0) result.add(cnt); } 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 →