Time Needed to Inform All Employees - Leetcode 1376 - Python

  Рет қаралды 10,808

NeetCodeIO

NeetCodeIO

Күн бұрын

Solving Leetcode 1376 - Time Needed to Inform All Employees, today's daily leetcode on June 2.
🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🥷 Discord: / discord
🐦 Twitter: / neetcode1
🐮 Support the channel: / neetcode
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
💡 DYNAMIC PROGRAMMING PLAYLIST: • House Robber - Leetco...
Problem Link: leetcode.com/problems/time-ne...
0:00 - Read the problem
0:35 - Drawing Explanation
6:30 - Coding Explanation
leetcode 1376
#neetcode #leetcode #python

Пікірлер: 24
@manerivasanthkumar606
@manerivasanthkumar606 Жыл бұрын
bro update your website please
@uptwist2260
@uptwist2260 Жыл бұрын
Thanks for the daily ig kinda like max depth but weighted edges.
@anujapuranik2000
@anujapuranik2000 10 ай бұрын
This explanation is so simple and mad easy. Thankyou for all your work and efforts!
@MP-ny3ep
@MP-ny3ep Жыл бұрын
Beautifully explained. Thank you!
@krateskim4169
@krateskim4169 Жыл бұрын
Thank you
@manalitiwari3410
@manalitiwari3410 Жыл бұрын
Hi, Are you not uploading this new content on your Neetcode All list on the website?
@netanelkomm5636
@netanelkomm5636 Жыл бұрын
Damn, i spent like an hour trying to figure out what went wrong in my code. Eventually I realised that I used, i one place, informTime[i] (i.e the current employee) rather than informTime[headID]. I used dfs btw.
@daniel860305
@daniel860305 Жыл бұрын
Hi @NeetCodeIO, what do you think about starting DFS from the leaf node and traversing back to the root? That we wouldn't need to create another graph and it is possible to reach O(1) space complexity with path compression.
@Josh-lz9pd
@Josh-lz9pd Жыл бұрын
I thought about this too, I just think DFS would depend more on how lucky you get (because you need to get the leaf with the most expensive time costs)
@zweitekonto9654
@zweitekonto9654 Жыл бұрын
You would still require extra space to keep track of which leaf nodes and path you have traversed?
@daniel860305
@daniel860305 Жыл бұрын
@@zweitekonto9654 Actually not because by path compression I detach the visited nodes from the original tree (basically modify the manager array) so that I could retrieve the informTime of a visited node in O(1) time
@YT.Nikolay
@YT.Nikolay Жыл бұрын
Thanks for the video! But I think it should be: q = deque([(headID, informTime[headID])]), in case if it takes some time to inform head of managers
@deadlyecho
@deadlyecho Жыл бұрын
It is not mentioned in the problem statement that this could be the case, so it doesn't actually matter... both are correct
@NeetCodeIO
@NeetCodeIO Жыл бұрын
I believe informTime[headID] is the time it takes to inform employees of head, not head itself.
@julianelmasry9556
@julianelmasry9556 Жыл бұрын
why is adding the maxTime at each level incorrect? it makes sense to me but I fail at test case 8
@deadlyecho
@deadlyecho Жыл бұрын
If you are adding the max time at each level that means that you have assigned that level's manager some extra delay time to relay the info down to the employees which is not the case.. for the example shown below, if we follow your approach the result would be 5 but the correct result is 4 beacuse beacuse the process is done in parallel so taking the max and adding it, will add a delay to the result. 0 ( adds 1) / \ 1 (adds 1) 1 (adds 2) / \ / \ 2 2 (adds 2) 3 3 (adds 1) / \ /\ 5 5 4 4
@user-bj5pn1tf7o
@user-bj5pn1tf7o Жыл бұрын
I stuck in the same case and finally I figure out why. The inform passing path should be sequential. In case 8. 6->2 will take 975 and 8->5->0 will take 261+170. If you adding maxtime at each level you would have 6->2 adding 5->0 but its not a valid path.
@champion5946
@champion5946 Жыл бұрын
great
@michael._.
@michael._. Жыл бұрын
Dear Neetcode, could you do a video on **956. Tallest Billboard** when you are free? Always appreciating your videos, thank you ≧◉◡◉≦
@dossymzhankudaibergenov8193
@dossymzhankudaibergenov8193 Жыл бұрын
another version of problem "max sum from root to leaf"
@metarus208
@metarus208 Жыл бұрын
Hey Neetcode, I became a paid member of your website but there doesn't seem to be much content. Hope you're alright. Waiting for more uploads from you soon.
@liftandshiftdev3222
@liftandshiftdev3222 Жыл бұрын
1249ms runtime beats 80%. Wow. My java dfs only took 100 ms and cant beat 50%
@sumitsharma6738
@sumitsharma6738 Жыл бұрын
I Come up with some different approach but similar xD Build a Tree and finding the max time using postOrder Traversal class Solution { public int numOfMinutes(int n, int headID, int[] manager, int[] informTime) { List adj = new ArrayList(); for(int i=0;i
@satwiktatikonda764
@satwiktatikonda764 Жыл бұрын
why arent uplaoding daily LC🥲 ?we go through ur videos when ever we have any dbt ,cause ur explanation is the best
Why is everyone LYING?
7:56
NeetCodeIO
Рет қаралды 14 М.
Little girl's dream of a giant teddy bear is about to come true #shorts
00:32
Beautiful gymnastics 😍☺️
00:15
Lexa_Merin
Рет қаралды 14 МЛН
I Can't Believe We Did This...
00:38
Stokes Twins
Рет қаралды 127 МЛН
路飞被小孩吓到了#海贼王#路飞
00:41
路飞与唐舞桐
Рет қаралды 78 МЛН
EXCLUSIVE TIME OF FUNCTIONS | LEETCODE 636 | PYTHON SOLUTION
15:42
Cracking FAANG
Рет қаралды 3,9 М.
Crowdstrike broke the world: why system architecture matters
8:51
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 357 М.
Number of Enclaves - Leetcode 1020 - Python
11:39
NeetCodeIO
Рет қаралды 7 М.
11 Tips And Tricks To Write Better Python Code
11:00
Patrick Loeber
Рет қаралды 606 М.
Find Eventual Safe States - Leetcode 802 - Python
13:18
NeetCode
Рет қаралды 24 М.
All nodes distance K in binary tree | Leetcode #863
12:45
Techdose
Рет қаралды 8 М.
Little girl's dream of a giant teddy bear is about to come true #shorts
00:32