We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
functionhourglassSum(arr){// Write your code hereletn=arr.length-2lethighest=-Infinityfor(leti=0;i<n;i++){for(letj=0;j<n;j++){letk=arr[i].slice(j,j+3).reduce((x,y)=>x+y,0)letl=arr[i+1][j+1]letm=arr[i+2].slice(j,j+3).reduce((x,y)=>x+y,0)letsum=k+l+mhighest=Math.max(sum,highest)}}returnhighest}
Cookie support is required to access HackerRank
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 →
Javascript Solution