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

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

NeetCodeIO

NeetCodeIO

Күн бұрын

Пікірлер: 39
@NeetCodeIO
@NeetCodeIO 9 күн бұрын
love it when i get to break out the red shirt
@siddardha14
@siddardha14 8 күн бұрын
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
@mohammadrouzegar3275
@mohammadrouzegar3275 9 күн бұрын
Lovely solution! I like your approach that avoids using the 'visited' hash set.
@julianelmasry9556
@julianelmasry9556 9 күн бұрын
Self proclaimed and most voted GOAT
@greedyfishbones
@greedyfishbones 9 күн бұрын
7:15 the +1 caught so off guard i started wheezing
@strobes2638
@strobes2638 9 күн бұрын
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 9 күн бұрын
Strand is honestly a really good word for this, thanks for commenting. Really liked the way you explained it.
@strobes2638
@strobes2638 9 күн бұрын
@@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
@K9Megahertz
@K9Megahertz 9 күн бұрын
The real challenge to this problem is finding an applicable use case for it.
@baetz2
@baetz2 8 күн бұрын
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 8 күн бұрын
@@baetz2 Why would you use a tree? A flat list of workers would be better no?
@baetz2
@baetz2 8 күн бұрын
@@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.
@caiorenato1
@caiorenato1 9 күн бұрын
i wanna be good at leetcode, you are helping me alot, God bless your life my friend.
@henokassalif8175
@henokassalif8175 9 күн бұрын
My guy just pointed out all the questions I had with the problem examples / description in the first 2 mins of the video
@MP-ny3ep
@MP-ny3ep 9 күн бұрын
Terrific explanation ! You made a hard problem look easy
@shibambiswas
@shibambiswas 9 күн бұрын
7:15 Bro reminded us about this on the longest night of the year.
@SarweshParsewar
@SarweshParsewar 9 күн бұрын
yeah true😢
@AadiyKhan
@AadiyKhan 9 күн бұрын
6:26 nobody does it better than my goat
@johnniewalkerjohnniewalker2459
@johnniewalkerjohnniewalker2459 9 күн бұрын
Excellent solution!!!
@sirojiddinSoftwareEngineer
@sirojiddinSoftwareEngineer 8 күн бұрын
Good job
@Everafterbreak_
@Everafterbreak_ 9 күн бұрын
this one demotivated me really bad ngl
@adilansari-hq9ge
@adilansari-hq9ge 9 күн бұрын
Good to see you bro!
@kanjurer
@kanjurer 9 күн бұрын
Neetcode, can you solve the Tandoori Chicken problem next?
@Axel.Blazer
@Axel.Blazer 9 күн бұрын
what is the number or is this the exact title?
@imranaziz7479
@imranaziz7479 9 күн бұрын
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 9 күн бұрын
yes
@syuufukuinjp
@syuufukuinjp 9 күн бұрын
keep it up bro
@ahmedtremo
@ahmedtremo 9 күн бұрын
great video as usual :D
@mechano6505
@mechano6505 9 күн бұрын
My goat coming in clutch
@saketh8937
@saketh8937 8 күн бұрын
neetcode to the rescue!
@staywithmeforever
@staywithmeforever 8 күн бұрын
13:30 copying 0 😅
@tawfikkoptan5781
@tawfikkoptan5781 9 күн бұрын
MY GOAT 🔥❤️🔥❤️🔥❤️
@sauravsingh4497
@sauravsingh4497 8 күн бұрын
Its a good day when my goat posts
@prasanna.83
@prasanna.83 7 күн бұрын
Can anyone explain why he declines the claim he made earlier regarding that theoretical limit being 3?
@rajsuriyang3427
@rajsuriyang3427 8 күн бұрын
The reason we come here is for the math.
@unknown-mf7dd
@unknown-mf7dd 9 күн бұрын
fk this problem
@IamAWESOME3980
@IamAWESOME3980 9 күн бұрын
how the hell can people problem-solve to the answer here. this is such bs
@jchaodubs
@jchaodubs 8 күн бұрын
lebron
@NoobCoder-n7x
@NoobCoder-n7x 9 күн бұрын
First!
The only Cloud services you actually need to know
17:17
NeetCodeIO
Рет қаралды 206 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
W2L11_Greedy Fails on non-Matroid Structures
14:16
IIT Madras - B.S. Degree Programme
Рет қаралды 190
How I Approach a New Leetcode Problem (live problem solving)
25:31
Maximum Number of K Divisible Components | Leetcode 2872
16:55
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 903 М.
The Dome Paradox: A Loophole in Newton's Laws
22:59
Up and Atom
Рет қаралды 1,2 МЛН
When Optimisations Work, But for the Wrong Reasons
22:19
SimonDev
Рет қаралды 1,1 МЛН
Making an Algorithm Faster
30:08
NeetCodeIO
Рет қаралды 181 М.
Web Developers Are Disconnected
21:36
ThePrimeTime
Рет қаралды 184 М.
Microservices are Technical Debt
31:59
NeetCodeIO
Рет қаралды 703 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН