Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Employee Importance
Bookmark
DFS
BFS
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
id
→
employee, for O(1) lookup
1
1
5
2
2
3
3
3
3
query
total +=
dfs(2)
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
return
3
for 2
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
dfs(3)
total =
3
5
3
3
1
1
5
2
2
3
3
3
3
3
3
query
return
3
for 3
5
3
3
1
1
5
11
2
2
3
3
3
3
3
3
query
return
11
for 1
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 / 12
Input
Two reports
Query a leaf
Three levels
Custom
employees
=
[[1,5,[2,3]],[2,3,[]],[3,3,[]]]
,
id
=
1
0 / 12
algo
master
.
io
Step:
Sum the importance of employee 1 and everyone below them in the hierarchy