Maximum Number of K-Divisible Components - Leetcode 2872 - Python

  Рет қаралды 7,932

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 39
@NeetCodeIO
@NeetCodeIO Ай бұрын
love it when i get to break out the red shirt
@siddardha14
@siddardha14 Ай бұрын
Instead of returning total, if we included the component in our sum, we could return 0 from the recursion which would solve the way of counting too
@julianelmasry9556
@julianelmasry9556 Ай бұрын
Self proclaimed and most voted GOAT
@mohammadrouzegar3275
@mohammadrouzegar3275 Ай бұрын
Lovely solution! I like your approach that avoids using the 'visited' hash set.
@greedyfishbones
@greedyfishbones Ай бұрын
7:15 the +1 caught so off guard i started wheezing
@strobes2638
@strobes2638 Ай бұрын
Probably just me having no attention span, but I feel like the contradiction proof explanation wasn't super intuitive even though I solved it before watching, so I wanted to post my thought process even though it's basically the same thing. The way I thought about it was: since the sum of all nodes is divisible by k, whenever we traverse the graph and find a connected set of nodes divisible by k, the sum of the remaining nodes branching off in the graph are also divisible by k. Is there any reason we can't pop it immediately?-> if there are any subtrees branching off not divisible by k that we would "strand". To avoid this, we just work bottom up from the leaf nodes using postorder traversal so we can always pop a component off as soon as the sum is divisible since there's nothing to "strand".
@NeetCodeIO
@NeetCodeIO Ай бұрын
Strand is honestly a really good word for this, thanks for commenting. Really liked the way you explained it.
@strobes2638
@strobes2638 Ай бұрын
@@NeetCodeIO thanks! I still got a lot from watching your implementation, I wasted a lot of memory on my recursion doing a bunch of stuff like passing a visited node set instead of just keeping track of the parent lmao
@caiorenato1
@caiorenato1 Ай бұрын
i wanna be good at leetcode, you are helping me alot, God bless your life my friend.
@henokassalif8175
@henokassalif8175 Ай бұрын
My guy just pointed out all the questions I had with the problem examples / description in the first 2 mins of the video
@shibambiswas
@shibambiswas Ай бұрын
7:15 Bro reminded us about this on the longest night of the year.
@SarweshParsewar
@SarweshParsewar Ай бұрын
yeah true😢
@K9Megahertz
@K9Megahertz Ай бұрын
The real challenge to this problem is finding an applicable use case for it.
@baetz2
@baetz2 Ай бұрын
Imagine you have a distributed map-reduce or stream-processing system, and a pool of workers with a tree-like workflow. Some parts of the workflow are calculation-heavy, while others are lighter. Your task is to partition this workflow into equally performant subtrees to put them to different machines. Let's say k is performance unit of a subtree, so if one subtree consumes 2k and other consumes 3k, then you use a cluster of 2 machines for the first subtree and 3 machines for the second.
@K9Megahertz
@K9Megahertz Ай бұрын
@@baetz2 Why would you use a tree? A flat list of workers would be better no?
@baetz2
@baetz2 Ай бұрын
@@K9Megahertz I would use a tree if the workflows were heterogenous and branching. Something where we want to separate concerns, handle errors independently, scale independently. A map-reduce system can be a tree like that with one of the nodes being a pool of mappers and another - a pool of reducers. Disclaimer: I haven't build systems like that irl, it's just my attempt to come up with a use case for this problem.
@MP-ny3ep
@MP-ny3ep Ай бұрын
Terrific explanation ! You made a hard problem look easy
@AadiyKhan
@AadiyKhan Ай бұрын
6:26 nobody does it better than my goat
@johnniewalkerjohnniewalker2459
@johnniewalkerjohnniewalker2459 Ай бұрын
Excellent solution!!!
@adilansari-hq9ge
@adilansari-hq9ge Ай бұрын
Good to see you bro!
@sirojiddinSoftwareEngineer
@sirojiddinSoftwareEngineer Ай бұрын
Good job
@imranaziz7479
@imranaziz7479 Ай бұрын
So basically, every time we run dfs, we are checking to see if we can break off the connection between cur and parent, which will add one more connected component?
@randheerkumargautam6433
@randheerkumargautam6433 Ай бұрын
yes
@ahmedtremo
@ahmedtremo Ай бұрын
great video as usual :D
@kanjurer
@kanjurer Ай бұрын
Neetcode, can you solve the Tandoori Chicken problem next?
@Axel.Blazer
@Axel.Blazer Ай бұрын
what is the number or is this the exact title?
@mechano6505
@mechano6505 Ай бұрын
My goat coming in clutch
@staywithmeforever
@staywithmeforever Ай бұрын
13:30 copying 0 😅
@syuufukuinjp
@syuufukuinjp Ай бұрын
keep it up bro
@Everafterbreak_
@Everafterbreak_ Ай бұрын
this one demotivated me really bad ngl
@saketh8937
@saketh8937 Ай бұрын
neetcode to the rescue!
@tawfikkoptan5781
@tawfikkoptan5781 Ай бұрын
MY GOAT 🔥❤️🔥❤️🔥❤️
@sauravsingh4497
@sauravsingh4497 Ай бұрын
Its a good day when my goat posts
@prasanna.83
@prasanna.83 Ай бұрын
Can anyone explain why he declines the claim he made earlier regarding that theoretical limit being 3?
@IamAWESOME3980
@IamAWESOME3980 Ай бұрын
how the hell can people problem-solve to the answer here. this is such bs
@unknown-mf7dd
@unknown-mf7dd Ай бұрын
fk this problem
@rajsuriyang3427
@rajsuriyang3427 Ай бұрын
The reason we come here is for the math.
@NoobCoder-n7x
@NoobCoder-n7x Ай бұрын
First!
@jchaodubs
@jchaodubs Ай бұрын
lebron
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
It’s all not real
00:15
V.A. show / Магика
Рет қаралды 20 МЛН
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
Maximum Number of K Divisible Components | Leetcode 2872
16:55
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 201 М.
are we cooked w/ o3?
13:58
ThePrimeTime
Рет қаралды 334 М.
Thoughts About Unit Testing | Prime Reacts
11:21
ThePrimeTime
Рет қаралды 245 М.
Minimum Cost For Tickets - Leetcode 983 - Python
22:46
NeetCodeIO
Рет қаралды 8 М.
Longest Repeating Character Replacement - Leetcode 424 - Python
20:44
Microservices are Technical Debt
31:59
NeetCodeIO
Рет қаралды 753 М.
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН