You are viewing a single comment's thread. Return to all comments →
function hourglassSum(arr: number[][]): number { // flatten array const result: number[] = arr.reduce((accumulator, value) => accumulator.concat(value), []); const extractHourGlass = (arr: number[], startIndex: number) => { return arr.slice(startIndex, startIndex+3) .concat(arr.slice(startIndex+7, startIndex+8)) .concat(arr.slice(startIndex+12, startIndex+15)); } const startIndces: number[] = [0,1,2,3, 6,7,8,9, 12,13,14,15, 18,19,20,21]; const hourglassSums: number[] = startIndces.map<number>((x) => { return extractHourGlass(result, x).reduce<number>((j, v) => { return j + v; }, 0) }, 0) console.log(hourglassSums); return Math.max(...hourglassSums); }
2D Array - DS
You are viewing a single comment's thread. Return to all comments →