Remix.run Logo
thaumasiotes 8 hours ago

> Hmm. Given such a triangle, let m be the largest number in the triangle. For each x in the triangle, replace it with m - x.

By the time you've actually done these two steps, you could have already finished the problem with a dynamic programming approach.

(Starting from the bottom row and working upward, replace each cell in the row with the length of the longest path from itself to the bottom, which you can know by checking which of its two children has the longer path associated.)