You are viewing a single comment's thread. Return to all comments →
without using while. It just uses sort and 1 loop to reach to answer
vector<int> cutTheSticks(vector<int> arr) { sort(arr.begin(), arr.end()); vector<int> result; result.push_back(arr.size()); int smallest = arr[0]; for(int i=0; i < arr.size(); i++) { int elem = arr[i] - smallest; if(elem > 0) { result.push_back(arr.size()-i); smallest += elem; } } return result; }
Cut the sticks
You are viewing a single comment's thread. Return to all comments →
without using while. It just uses sort and 1 loop to reach to answer