Created
April 15, 2020 17:10
-
-
Save MagedAhmad/f333d100f2c2d0add7e28f1f346ead89 to your computer and use it in GitHub Desktop.
Hackerrank 2D Array DS
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
| <?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