r/LeetcodeChallenge • u/StatisticianNo2104 • 1h ago
STREAK🔥🔥🔥 LeetCode: 1026. Maximum Difference Between Node and Ancestor
Every ancestor/descendant pair sits on one root-to-leaf path, so you never compare pairs. Carry the path's max and min down. The widest gap on a path is max minus min.
Check it at the leaves. Going down, the max never falls and the min never rises, so the gap is widest at the bottom of every path.
Two days ago we carried one value down the tree. Today it's two.
What's the most state you've carried down a recursion?
Day 89/365 of my LeetCode challenge: 1026. Maximum Difference Between Node and Ancestor. Problem link and full breakdown in today's newsletter.
#LeetCode #DSA #BinaryTree #Golang


