Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Employee Importance
Bookmark
Input
Two reports
Query a leaf
Three levels
Custom
employees
=
[[1,5,[2,3]],[2,3,[]],[3,3,[]]]
,
id
=
1
1
1
5
2
2
3
3
3
3
query
1
1
5
2
2
3
3
3
3
query
1
1
5
2
2
3
3
3
3
query
subordinates of 1:
[2, 3]
5
1
1
5
2
2
3
3
3
3
query
dfs(2)
total =
3
5
3
1
1
5
2
2
3
3
3
3
3
query
3
+ subordinates =
3
5
3
1
1
5
2
2
3
3
3
3
3
query
total = 5 +
3
=
8
5
3
1
1
5
2
2
3
3
3
3
3
query
total +=
dfs(3)
5
3
1
1
5
2
2
3
3
3
3
3
query
no subordinates
→
total = 3
5
3
3
1
1
5
2
2
3
3
3
3
3
3
query
return
3
5
3
3
1
1
5
11
2
2
3
3
3
3
3
3
query
5
+ subordinates =
11
5
3
3
1
1
5
11
2
2
3
3
3
3
3
3
query
return 11
5
3
3
algo
master
.
io
Step:
Sum the importance of employee 1 and everyone below them in the hierarchy
0 / 17
Input
Two reports
Query a leaf
Three levels
Custom
employees
=
[[1,5,[2,3]],[2,3,[]],[3,3,[]]]
,
id
=
1
0 / 17
algo
master
.
io
Step:
Sum the importance of employee 1 and everyone below them in the hierarchy