Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Maximum Difference Between Node and Ancestor

XPChallenge Points: 20
levelLevel: Medium

Given a binary tree root, find the maximum value of a.valb.val|a.val - b.val| over all pairs where aa is an ancestor of bb (ancestor means parent, grandparent, etc.).
Return that maximum difference.

Example 1:

Input: root = [8,3,10,1,6,null,14,null,null,4,7,13]

Output: 7

Example 2:

Input: root = [1,null,2,null,0,3]

Output: 3

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result