Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Maximum Difference Between Node and Ancestor
Bookmark
Input
Example 1
Example 2
Balanced Tree
Custom
tree
=
[8, 3, 10, 1, 6, null, 14, null, null, 4, 7, 13]
8
3
10
1
6
14
4
7
13
8
3
10
1
6
14
4
7
13
8
3
10
1
6
14
4
7
13
curr
[1,8]
dfs: node = 1, minVal = 1, maxVal = 8
Max Difference: 0
8
3
10
1
6
14
4
7
13
curr
[3,8]
7
dfs: node = 3, minVal = 3, maxVal = 8
Current Diff: 8 - 3 = 5
Left: 7
Max Difference: 7
8
3
10
1
6
14
4
7
13
7
Max Difference: 7
8
3
10
1
6
14
4
7
13
curr
[3,8]
7
5
dfs: node = 7, minVal = 3, maxVal = 8
Max Difference: 7
8
3
10
1
6
14
4
7
13
curr
[3,8]
7
5
dfs: node = 7, minVal = 3, maxVal = 8
Current Diff: 8 - 3 = 5
Left: 5, Right: 5
Max Difference: 7
8
3
10
1
6
14
4
7
13
7
5
5
5
7
Max Difference: 7
8
3
10
1
6
14
4
7
13
curr
[8,14]
7
5
5
5
7
dfs: node = 13, minVal = 8, maxVal = 14
Current Diff: 14 - 8 = 6
Max Difference: 7
8
3
10
1
6
14
4
7
13
curr
[8,14]
7
5
5
5
7
6
dfs: node = 14, minVal = 8, maxVal = 14
Current Diff: 14 - 8 = 6
Left: 6
Max Difference: 7
8
3
10
1
6
14
4
7
13
7
5
5
5
7
6
6
6
Max Difference: 7
algo
master
.
io
Step:
Start: Find maximum difference between node and ancestor
0 / 85
Input
Example 1
Example 2
Balanced Tree
Custom
tree
=
[8, 3, 10, 1, 6, null, 14, null, null, 4, 7, 13]
0 / 85
algo
master
.
io
Step:
Start: Find maximum difference between node and ancestor