You are viewing a single comment's thread. Return to all comments →
Here's my solution in JS.
function hourglassSum(arr) { let largestSum = NaN const [hgHeight, hgWidth] = [3, 3] for (let row = 0; row <= hgHeight; row++) { for (let j = 0; j <= hgWidth; j++) { let sum = 0 for (let c = 0; c < hgWidth; c++) { sum += arr[row][c+j] + arr[row+2][c+j] if (c == 1) { sum += arr[row+1][c+j] } } if (isNaN(largestSum) || sum > largestSum) { largestSum = sum } } } return largestSum; }
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 →
Here's my solution in JS.