So, basically I'm feeling incredibly dumb, because of this exercise, I've spent like 4 or 5 hours trying to code it, and so far I've not been successful.
I have come to the realization that this one is easier to solve with a tree traversal using the Longest Path approach, But I'm not sure (Could you please confirm this to me.), could be over-kill since it's supposed to be one of the easy problems, So Could you please help me with some guidance or basic steps or algorithm approaches on how to solve this one? all kinds of help is certainly appreciated.
PS. I usually post some code about what I've done so far, but I believe that to this point everything has been so wrong that I prefer to start from scratch, at least in terms of ideas.
Thanks.
As per-request, here's the Code I typed according to the accepted answer to solve the Exercise:
def get_max_sum(matrix)
(1...matrix.length).each do |index|
flag = 0
matrix[index].each_with_index do |e, i|
add = (matrix[index-1][flag] > matrix[index-1][flag+1]) ? matrix[index-1][flag] : matrix[index-1][flag+1]
e += add
matrix[index][i] = e
flag = flag + 1
end
end
matrix[-1][0]
end
Where the matrix param is an array of arrays, each one representing a row from the triangle.