You are viewing a single comment's thread. Return to all comments →
I made my solution using a minHeap Idea.
vector <int> cutTheSticks(const vector <int> &arr) { priority_queue <int, vector<int>, greater<int> > minHeap; for(int x: arr){ minHeap.push(x); } int nStickCutted = arr.size(); int cuttedSize = 0; vector<int> ans; int counter = 0; while(!minHeap.empty()){ if((minHeap.top() - cuttedSize) == 0){ ans.push_back(nStickCutted); while(((minHeap.top() - cuttedSize) == 0) && !minHeap.empty() ){ --nStickCutted; minHeap.pop(); } } else{ cuttedSize = minHeap.top(); } } 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 →
I made my solution using a minHeap Idea.