Skip to main content
Advancedcoding Verified

In a binary tree, find the maximum sum of a path between any two leaves; as a follow-up, return the path itself.

ReportedSource: GeeksforGeeks interview experience: Microsoft SDE-I, 1+ year

Quick answerFree

Post-order DFS returning the best root-to-leaf sum per node; at nodes with two children update answer with left + right + val. Track best child pointers to rebuild the path. O(n).

Detailed answer· ~110 words

Pro

Unlock the full answer with Pro

Get a ~110-word model answer and a runnable reference solution, plus 82 more DSA questions.

Reference solution· runs in the browser sandbox

Pro
Unlock with Pro

+ 82 more DSA questions in Pro, each with the full answer.

Discussion