You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master , feel free to give a star :) )
std::string gameOfThrones(std::string _key){ if(_key.size() == 1){ return "YES"; } bool isMedianFound = false; bool isSzEven = !_key.size() % 2; std::sort(_key.begin(), _key.end()); for(auto it1 = _key.cbegin(), it2 = it1 + 1; it1 != _key.cend(); ++it2){ if(*it1 == *it2){ it1 = ++it2; }else{ if(isMedianFound || isSzEven){ return "NO"; } isMedianFound = true; it1 = it2; } } return "YES"; }
Seems like cookies are disabled on this browser, please enable them to open this website
Game of Thrones - I
You are viewing a single comment's thread. Return to all comments →
C++ (more at https://github.com/IhorVodko/Hackerrank_solutions/tree/master , feel free to give a star :) )