• [deleted]
    + 1 comment

    SImple Python solution: We need to initialize count to -64 as matrix will be always 6*6 and values must be -9<=x<=9. So if all values will be -9 in that case we will get -63 as max value. Pass all test cases

    def hourglassSum(arr):
        count = -64
        row = 0
        col = 0
        while row < 4 :
            temp = arr[row][col] + arr[row][col+1]+arr[row][col+2]+arr[row+1][col+1] + arr[row+2][col]+arr[row+2][col+1]+ arr[row+2][col+2]
            if temp > count:
                count = temp
            col +=1
            if col == 4:
                col = 0
                row +=1
        return count