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 nonDivisibleSubset( int const & _k, std::vector<int> const & _set ){ using namespace std; auto countReminders = vector<size_t>(_k, 0); for(auto & num : _set){ ++countReminders.at(num % _k); } auto first = begin(countReminders); auto last = --end(countReminders); size_t sz = 0; if(*first++ != 0){ ++sz; } while(first < last){ sz += max(*first++, *last--); }; return (first == last && *first != 0) ? ++sz : sz; }
Seems like cookies are disabled on this browser, please enable them to open this website
Non-Divisible Subset
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 : ) )