You are viewing a single comment's thread. Return to all comments →
my JavaScript solution (h= horizontal and v=vertical direction).
function hourglassSum(arr) { let h= 0; let v= 0; let sum =0; let max=Number.MIN_SAFE_INTEGER; while ((h+2) < arr.length) { v=0; while ((v+2) < arr.length) { sum=0; for (let i=0+h ; i < (3+h); i++) { sum = sum + arr[v][i]; sum = sum + arr[v+2][i]; } sum = sum + arr[v+1][h+1]; if (sum > max) { max= sum; } v++; } h++; } return max; }
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 JavaScript solution (h= horizontal and v=vertical direction).