Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rodrigopuls/d314d91eda8dc7a95c5d4f87e6d8a952 to your computer and use it in GitHub Desktop.
Save rodrigopuls/d314d91eda8dc7a95c5d4f87e6d8a952 to your computer and use it in GitHub Desktop.
public static int hourglassSum(List<List<int>> arr)
{
var max = -63; // 7 * -9 lower value possible
for (var i = 0; i < 4; i++) { // 4 row possibilities
for (var j = 0; j < 4; j++) // 4 column possibilities
{
var sum = 0;
sum = (arr[i][j] + arr[i][j + 1] + arr[i][j + 2] + arr[i + 1][j + 1] + arr[i + 2][j] +
arr[i + 2][j + 1] + arr[i + 2][j + 2]);
max = max < sum ? sum : max;
}
}
return max;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment