Project Euler #67: Maximum path sum II

  • + 0 comments

    Here is my Python 3 100/- Points solution

    def find_maximum_total(triangle):
        n = len(triangle)
    
        for i in range(n - 2, -1, -1):
            for j in range(len(triangle[i])):
                triangle[i][j] += max(triangle[i+1][j], triangle[i+1][j+1])
    
        return triangle[0][0]
    
    # Read the number of testcases
    t = int(input().strip())
    
    for _ in range(t):
        n = int(input().strip())
        triangle = []
        for _ in range(n):
            row = list(map(int, input().strip().split()))
            triangle.append(row)
    
        result = find_maximum_total(triangle)
        print(result)