I have some questions about getting maximum sum value in binary tree.
Each node can have two child nodes (Left, Right)
Sum[7, 3, 8, 7, 5] is the maximum sum value for the example above.
First, I thought choosing each max child node is best answer, but it is not.
triangle = [[7], [3, 8], [8, 1, 0], [2, 7, 4, 4], [4, 5, 2, 6, 5]]
depth = 0
total = []
N = triangle[0][0]
def min_max(depth, N, total):
if (depth+1) == len(triangle):
return total
else:
a,b = triangle[depth+1][triangle[depth].index(N)], triangle[depth+1][triangle[depth].index(N)+1]
total.append(max(a,b))
N = max(a,b)
return min_max(depth+1, N, total)
min_max(depth, N, total) # [8, 1, 7, 5]
Then, I thought getting all cases sum and comparing, but it seems to worsen the time complexity.
What is the proper algorithm for this task?

[7, 3, 8, 7, 5]is the answer.