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.
functionmain(){letarr=Array(6);for(leti=0;i<6;i++){arr[i]=readLine().replace(/\s+$/g,'').split(' ').map(arrTemp=>parseInt(arrTemp,10));}varhgSum=-9*7;//smallest possible hourglass sum//loop through the lines until the hourglass is reaching the bottomfor(letl=0;l<arr.length-2;l++){constarrLine=arr[l];//loop through the line until the top of the hourglass reaches the end of the linefor(leti=0;i<arr[l].length-2;i++){varhourglass=arrLine.slice(i,i+3);//hourglass tophourglass.push(arr[l+1][i+1]);//hourglass waisthourglass.push(...arr[l+2].slice(i,i+3));//hourglass bottom// console.log(hourglass);vartempSum=hourglass.reduce((a,b)=>a+b);// console.log(tempSum);if(tempSum>hgSum){hgSum=tempSum;}}}console.log(hgSum);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 11: 2D Arrays
You are viewing a single comment's thread. Return to all comments →
JS