Hackerrank: 2D Array - DS Solution
1function hourglassSum(arr) {2 const N = arr.length3 const M = arr[0].length4 let max = -Infinity56 for (let i = 0; i < N - 2; i++) {7 for (let j = 0; j < M - 2; j++) {8 max = Math.max(9 max,10 arr[i][j] +11 arr[i][j + 1] +12 arr[i][j + 2] +13 arr[i + 1][j + 1] +14 arr[i + 2][j] +15 arr[i + 2][j + 1] +16 arr[i + 2][j + 2]17 )18 }19 }2021 return max22}
Comments
Loading comments...
Tags
hackerrank
array
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.
Next Post
Codility: Peaks
Lesson 10 Prime and Composite Numbers
Previous Post
Codility: MaxProfit
Lesson 9 Maximum Slice Problem