• + 0 comments
    def hourglassSum(arr):
        # Write your code here
        sol=float("-inf")
        for i in range(len(arr)-2):
            for j in range(len(arr)-2):
                top=arr[i][j]+arr[i][j+1]+arr[i][j+2]
                middle=arr[i+1][j+1]
                bottom=arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2]
                current_sol=top+middle+bottom
                if current_sol>sol:
                    sol=current_sol
        return sol