Skip to content

Instantly share code, notes, and snippets.

@MagedAhmad
Created April 15, 2020 17:10
Show Gist options
  • Select an option

  • Save MagedAhmad/f333d100f2c2d0add7e28f1f346ead89 to your computer and use it in GitHub Desktop.

Select an option

Save MagedAhmad/f333d100f2c2d0add7e28f1f346ead89 to your computer and use it in GitHub Desktop.
Hackerrank 2D Array DS
<?php
function hourglassSum($arr) {
for($i = 0; $i < count($arr) - 2; $i++) {
for($j = 0; $j < count($arr[$i]) - 2; $j++) {
$results[] = $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];
}
}
return max($results);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment