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 equalStacks( std::vector<int> const & _h1 , std::vector<int> const & _h2 , std::vector<int> const & _h3 ){ using namespace std; auto sum1 = accumulate(cbegin(_h1), cend(_h1), 0); auto sum2 = accumulate(cbegin(_h2), cend(_h2), 0); auto sum3 = accumulate(cbegin(_h3), cend(_h3), 0); auto it1 = begin(_h1); auto it2 = begin(_h2); auto it3 = begin(_h3); while(!(sum1 == sum2 && sum2 == sum3)){ if(sum1 >= sum2 && sum1 >= sum3){ sum1 -= *it1++; } else if(sum2 >= sum3){ sum2 -= *it2++; } else{ sum3 -= *it3++; } } return sum1; }
Seems like cookies are disabled on this browser, please enable them to open this website
Equal Stacks
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 :) )