File tree 2 files changed +42
-0
lines changed
2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 521
521
687|[ Longest Univalue Path] ( ./0687-longest-univalue-path.js ) |Medium|
522
522
688|[ Knight Probability in Chessboard] ( ./0688-knight-probability-in-chessboard.js ) |Medium|
523
523
689|[ Maximum Sum of 3 Non-Overlapping Subarrays] ( ./0689-maximum-sum-of-3-non-overlapping-subarrays.js ) |Hard|
524
+ 690|[ Employee Importance] ( ./0690-employee-importance.js ) |Medium|
524
525
693|[ Binary Number with Alternating Bits] ( ./0693-binary-number-with-alternating-bits.js ) |Easy|
525
526
695|[ Max Area of Island] ( ./0695-max-area-of-island.js ) |Medium|
526
527
696|[ Count Binary Substrings] ( ./0696-count-binary-substrings.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 690. Employee Importance
3
+ * https://leetcode.com/problems/employee-importance/
4
+ * Difficulty: Medium
5
+ *
6
+ * You have a data structure of employee information, including the employee's unique ID,
7
+ * importance value, and direct subordinates' IDs.
8
+ *
9
+ * You are given an array of employees employees where:
10
+ * - employees[i].id is the ID of the ith employee.
11
+ * - employees[i].importance is the importance value of the ith employee.
12
+ * - employees[i].subordinates is a list of the IDs of the direct subordinates of the ith employee.
13
+ *
14
+ * Given an integer id that represents an employee's ID, return the total importance value of this
15
+ * employee and all their direct and indirect subordinates.
16
+ */
17
+
18
+ /**
19
+ * Definition for Employee.
20
+ * function Employee(id, importance, subordinates) {
21
+ * this.id = id;
22
+ * this.importance = importance;
23
+ * this.subordinates = subordinates;
24
+ * }
25
+ */
26
+
27
+ /**
28
+ * @param {Employee[] } employees
29
+ * @param {number } id
30
+ * @return {number }
31
+ */
32
+ var GetImportance = function ( employees , id ) {
33
+ const map = new Map ( employees . map ( e => [ e . id , e ] ) ) ;
34
+ return dfs ( id ) ;
35
+
36
+ function dfs ( id ) {
37
+ if ( ! map . has ( id ) ) return 0 ;
38
+ const e = map . get ( id ) ;
39
+ return e . importance + e . subordinates . reduce ( ( sum , id ) => sum + dfs ( id ) , 0 ) ;
40
+ }
41
+ } ;
You can’t perform that action at this time.
0 commit comments