690. Employee Importance
doing some more basic questions before the next tech round.
1"""
2# Definition for Employee.
3class Employee:
4 def __init__(self, id: int, importance: int, subordinates: List[int]):
5 self.id = id
6 self.importance = importance
7 self.subordinates = subordinates
8"""
9
10
11class Solution:
12 def getImportance(self, employees: List["Employee"], id: int) -> int:
13
14 employee_dict = {}
15
16 for e in employees:
17 employee_dict[e.id] = [e.importance, e.subordinates]
18
19 dq = deque([id])
20 result = 0
21
22 while dq:
23 importance, subordinates = employee_dict[dq.popleft()]
24 result += importance
25
26 for s in subordinates:
27 dq.append(s)
28
29 return result
#Array #Hashing #Breadth-First-Search #Python