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 :) )
int beautifulPairs( std::vector<int> _v1 , std::vector<int> _v2 ){ std::map<int, size_t> map1; std::map<int, size_t> map2; for(auto const & x : _v1){ ++map1[x]; } for(auto const & x : _v2){ ++map2[x]; } size_t pairs = 0; bool hasExtraPair = false; for(auto const & pair : map1){ if(map2.find(pair.first) != map2.cend()){ pairs += std::min(pair.second, map2[pair.first]); }else{ hasExtraPair = true; } } return hasExtraPair ? ++pairs : --pairs; }
Seems like cookies are disabled on this browser, please enable them to open this website
Beautiful Pairs
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 :) )