You are viewing a single comment's thread. Return to all comments →
public static List cutTheSticks(List arr) { ArrayList ans = new ArrayList<>(); Collections.sort( arr ); ans.add( arr.size()); if(arr.size() == 1) return ans; while( arr.size( ) >1){ int num = arr.get(0); int idx = arr.size(); for( int i =0; i < arr.size() ; i++){ if ( arr.get (i) > num){ idx = i; break; } } while(idx>0){ arr.remove(0); idx--; } if(arr.size() != 0) ans.add(arr.size()); } return ans;
}
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 →
public static List cutTheSticks(List arr) { ArrayList ans = new ArrayList<>(); Collections.sort( arr ); ans.add( arr.size()); if(arr.size() == 1) return ans; while( arr.size( ) >1){ int num = arr.get(0); int idx = arr.size(); for( int i =0; i < arr.size() ; i++){ if ( arr.get (i) > num){ idx = i; break; } } while(idx>0){ arr.remove(0); idx--; } if(arr.size() != 0) ans.add(arr.size()); } return ans;