You are viewing a single comment's thread. Return to all comments →
JavaScript (Node.js) Solution
function equalStacks(h1, h2, h3) { let sum1 = h1.reduce((accumulator, currentValue) => accumulator + currentValue); let sum2 = h2.reduce((accumulator, currentValue) => accumulator + currentValue); let sum3 = h3.reduce((accumulator, currentValue) => accumulator + currentValue); let m; while (sum1 !== sum2 || sum2 !== sum3) { m = Math.max(sum1, sum2 ,sum3); if (m === sum1) { sum1 -= (h1.shift()); } else if (m === sum2) { sum2 -= (h2.shift()); } else if (m === sum3) { sum3 -= (h3.shift()); } } 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 →
JavaScript (Node.js) Solution