Created
September 17, 2020 19:21
-
-
Save andrewsafwatsamuel/80e8ac6c244bb0b91c1d3e0cbee6bfc9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun hourglassSum(arr: Array<Array<Int>>): Int { | |
val values = arrayListOf<Int>() | |
for (i in 0 until (arr.size - 2)) { | |
for (j in 0 until (arr[i].size - 2)) { | |
val current = arr[i] | |
val currentP1 = arr[i + 1] | |
val currentP2 = arr[i + 2] | |
val sum = current[j] + current[j + 1] + current[j + 2] + currentP1[j + 1] + currentP2[j] + currentP2[j + 1] + currentP2[j + 2] | |
values.add(sum) | |
} | |
} | |
return values.max()?:0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment