You are viewing a single comment's thread. Return to all comments →
C++ O(n log(n)) solution:
vector<int> cutTheSticks(vector<int> arr) { vector<int> result; int cumulative_cut {0}; sort(arr.begin(), arr.end(), greater<int>()); while (arr.size() > 0){ result.push_back(arr.size()); cumulative_cut += arr.back()-cumulative_cut; while (arr.size() > 0 && arr.back()-cumulative_cut <= 0) arr.pop_back(); } 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 →
C++ O(n log(n)) solution: