Back to course home
0% completed
Vote For New Content
Maximum Difference Between Node and Ancestor (medium)
Problem Statement
Given a root of the binary tree, return the maximum absolute difference in value between any node in a binary tree and its any ancestor.
A node a is the ancestor of node b if node a precedes node b in the path from the root to node b.
Examples
Example 1:
- Input: root = [5, 3, 8, 0, null, 4, 7, 1]
- Expected Output: 5
- Justification: The maximum difference is between node 0 and its ancestor 5, which is 5.
Example 2:
- Input: root = [2, 1, 3]
- Expected Output: 1
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page