Tap here to switch tabs
Problem
Submissions

Problem: Maximum Difference Between Node and Ancestor

Try to solve the Maximum Difference Between Node and Ancestor problem.

Statement

Given the root of a binary tree, determine the maximum value vv such that there exist distinct nodes aa and bb where v=∣aext.val−bext.val∣v = |a ext{.val} - b ext{.val}| and aa is an ancestor of bb.

Note: A node aa is an ancestor of bb if any child of aa is equal to bb or any child of aa is an ancestor of bb.

Constraints:

  • The number of nodes in the tree is in the range [2,5000][2, 5000].

  • 0≤0 \leq Node.val ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Difference Between Node and Ancestor

Try to solve the Maximum Difference Between Node and Ancestor problem.

Statement

Given the root of a binary tree, determine the maximum value vv such that there exist distinct nodes aa and bb where v=∣aext.val−bext.val∣v = |a ext{.val} - b ext{.val}| and aa is an ancestor of bb.

Note: A node aa is an ancestor of bb if any child of aa is equal to bb or any child of aa is an ancestor of bb.

Constraints:

  • The number of nodes in the tree is in the range [2,5000][2, 5000].

  • 0≤0 \leq Node.val ≤105\leq 10^5