You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) )
int toys(std::vector<int> _weights) { static constexpr int limit = 4; std::sort(_weights.begin(), _weights.end()); size_t containers = 1; for(auto it1 = _weights.cbegin(), it2 = it1 + 1; it2 != _weights.cend(); ++it2 ){ if(*it2 > *it1 + limit){ it1 = it2; ++containers; } } return containers; }
Seems like cookies are disabled on this browser, please enable them to open this website
Priyanka and Toys
You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) )