You are viewing a single comment's thread. Return to all comments →
Typescript/JavaScript solution
function equalStacks(h1: number[], h2: number[], h3: number[]): number { let s1 = h1.reduce(((sum, h) => sum + h), 0); let s2 = h2.reduce(((sum, h) => sum + h), 0); let s3 = h3.reduce(((sum, h) => sum + h), 0); let [i, j, k] = [0, 0, 0]; while (i < h1.length && j < h2.length && k < h3.length) { if (s1 === s2 && s2 == s3) return s1; if (s1 >= s2 && s1 >= s3) { s1 -= h1[i++]; } else if (s2 >= s1 && s2 >= s3) { s2 -= h2[j++]; } else { s3 -= h3[k++]; } } return 0; }
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 →
Typescript/JavaScript solution