Skip to content

Commit 41a9554

Browse files
authored
Time Needed to Inform All Employees - Depth First Search (#158)
* Time needed to inform all employees Time needed to inform all employees - Depth First Search. * Update README.md
1 parent 0639807 commit 41a9554

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//CPP DFS SOLUTION
2+
3+
// Problem statement: Return the no of mins required to inform all employees about the urgent news
4+
5+
class Solution {
6+
public:
7+
vector<int> adjList[100005];
8+
9+
int dfs(int headID, vector<int>& informTime)
10+
{
11+
int maxTime=0;
12+
for(auto employee : adjList[headID])
13+
{
14+
maxTime=max(maxTime, dfs(employee, informTime));
15+
}
16+
return informTime[headID] + maxTime;
17+
}
18+
int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {
19+
for(int i=0;i<n;i++)
20+
{
21+
if(manager[i]!=-1)
22+
adjList[manager[i]].push_back(i);
23+
}
24+
return dfs(headID, informTime);
25+
}
26+
};
27+
28+
//Space Complexity: O(N)
29+
//Time Complexity : O(N)

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
335335
| 104 | [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) | [python](./Python/maximum-depth-of-binary-tree.py) | _O(n)_ | _O(n)_ | Easy | DFS | |
336336
| 112 | [Path Sum](https://leetcode.com/problems/path-sum/) | [Java](./Java/path-sum.java) | _O(n)_ | _O(n)_ | Easy | DFS | |
337337
| 110 | [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/) | [Java](./Java/Balanced-Binary-Tree.java) | _O(n)_ | _O(n)_ | Easy | DFS | |
338-
339-
<br/>
338+
| 1376 | [ Time Needed to Inform All Employees] (https://leetcode.com/problems/time-needed-to-inform-all-employees/) | [C++] | _O(n)_ | _O(n)_ | Medium | DFS | |
339+
|<br/>
340340
<div align="right">
341341
<b><a href="#algorithms">⬆️ Back to Top</a></b>
342342
</div>

0 commit comments

Comments
 (0)