Brick Wall LeetCode solution in JavaScript
1var leastBricks = function (wall) {2const hash = wall.reduce((map, row) => {3let sum = 0;45for (let index = 0; index < row.length - 1; index++) {6sum += row[index];7const hashCount = map.get(sum) ?? 0;8map.set(sum, hashCount + 1);9}10return map;11}, new Map());1213let result = wall.length;14hash.forEach((value) => (result = Math.min(result, wall.length - value)));1516return result;17};