We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
int equalStacks(vector h1, vector h2, vector h3)
{
int n1= accumulate (h1.begin(),h1.end(),0);
int n2= accumulate (h2.begin(),h2.end(),0);
int n3= accumulate (h3.begin(),h3.end(),0);
while(true)
{
if (n1==n2 && n2==n3)
{
break;
}
if (n1>=n2 && n1>=n3)
{
n1=n1-h1.front();
h1.erase(h1.begin());
}
else if (n2>=n1 && n2>=n3)
{
n2=n2-h2.front();
h2.erase(h2.begin());
}
else if (n3>=n1 && n3>=n1)
{
n3=n3-h3.front();
h3.erase(h3.begin());
}
}
return n1;
}
Cookie support is required to access HackerRank
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 →
int equalStacks(vector h1, vector h2, vector h3) { int n1= accumulate (h1.begin(),h1.end(),0); int n2= accumulate (h2.begin(),h2.end(),0); int n3= accumulate (h3.begin(),h3.end(),0);
}