We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Cut the sticks
Cut the sticks
Sort by
recency
|
2049 Discussions
|
Please Login in order to post a comment
How is this question different from just iteratively removing the smallest elements? I tried the following, and it passes test cases, but fails most of the others.
List number = new List(); while (arr.Count > 0) { number.Add(arr.Count); arr.RemoveAll(i => i == arr.Min()); } return number;
one of cpp solution
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;
I am getting the required Output in Debug output using Python 3, but still throws an error.
Any feedback is welcome. TIA
Pasting the code below: