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.
#include <vector>#include <iostream>#include <algorithm>intmain(){usingnamespacestd;intN;autoless_then_1=[](intn)->bool{returnn<1;};cin>>N;vector<int>arr(N);for(inti=0;i<N;++i)cin>>arr[i];intprev_size=arr.size();while(!arr.empty()){cout<<prev_size<<endl;intminim=*min_element(arr.begin(),arr.end());for(int&n:arr){n=n-minim;}// Remove elements which are less then 1arr.erase(remove_if(arr.begin(),arr.end(),less_then_1),arr.end());prev_size=arr.size();// Update the count of elements}}
Cookie support is required to access HackerRank
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 →
My C++ solution with C++11 style. https://www.hackerrank.com/challenges/cut-the-sticks/submissions/code/18237551