You are viewing a single comment's thread. Return to all comments →
Kotlin
fun hourglassSum(arr: Array<Array<Int>>): Int { var max = Int.MIN_VALUE for (r in 0 until 4) { for (c in 0 until 4) { val rowTop = arr[r] val rowBottom = arr[r + 2] val sumRowTop = rowTop[c] + rowTop[c + 1] + rowTop[c + 2] val sumRowMiddle = arr[r + 1][c + 1] val sumRowBottom = rowBottom[c] + rowBottom[c + 1] + rowBottom[c + 2] val sum = sumRowTop + sumRowMiddle + sumRowBottom if (sum > max) max = sum } } 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 →
Kotlin