You are viewing a single comment's thread. Return to all comments →
My solution in JavaScript :-)
function hourglassSum(arr) { let sum = -Infinity; for (let i = 0; i <= 3; i++) { for (let j = 0; j <= 3; j++) { let a = arr[i][j]; let b = arr[i][j + 1]; let c = arr[i][j + 2]; let d = arr[i + 1][j + 1]; let e = arr[i + 2][j]; let f = arr[i + 2][j + 1]; let g = arr[i + 2][j + 2]; if (a + b + c + d + e + f + g > sum) { sum = a + b + c + d + e + f + g; } } } return sum; }
Seems like cookies are disabled on this browser, please enable them to open this website
2D Array - DS
You are viewing a single comment's thread. Return to all comments →
My solution in JavaScript :-)