You are viewing a single comment's thread. Return to all comments →
Dear I have some approach like you but instead of using min I calaculate Max but it fails in some test cases could you help me
function equalStacks(h1, h2, h3) { var sum1 = h1.reduce((a, b) => a + b, 0); var sum2 = h2.reduce((a, b) => a + b, 0); var sum3 = h3.reduce((a, b) => a + b, 0); while (true) { if (sum1 === sum2 && sum2 === sum3) break; var max = Math.max(sum1, sum2, sum3) if (sum1 === max) { sum1 -= h1.shift(); } if (sum2 === max) { sum2 -= h2.shift(); } if (sum3 === max) { sum3 -= h3.shift(); } } if (sum1 === sum2 && sum2 === sum3) return sum1;
}
Equal Stacks
You are viewing a single comment's thread. Return to all comments →
Dear I have some approach like you but instead of using min I calaculate Max but it fails in some test cases could you help me
}