Remove Max Number of Edges to Keep Graph Fully Traversable - Leetcode 1579 - Python

preview_player
Показать описание

Solving Leetcode 1579 - Remove Max Number of Edges to Keep Graph Fully Traversable, todays daily leetcode problem on April 29.

0:00 - Read the problem
2:00 - Drawing Explanation
13:00 - Coding Explanation

leetcode 1579

#neetcode #leetcode #python
Рекомендации по теме
Комментарии
Автор


Looking forward to next month btw - hopefully not a Hard problem every f*cking day xD

NeetCodeIO
Автор

15:58 "we want to increment count by 1 pretty much every time" -- obvs this is hyperbole, but for anyone actually curious you do still need to check the union result of type 3 edges for alice and bob, so if you don't like bitwise OR operator you could do:
cnt += max(alice.union(src, dst), bob.union(src, dst)) for same effect, or have your union return True/False, etc

def__init
Автор

9:56 You misspoke here. It's not the green edges that are traversable for both Alice and Bob but the blue one. Leaving the comment so other people don't get confused.

aadil
Автор

Thanks man. I was able to solve the question on my own this time but it wouldn’t have been possible without your content.

aniketmahangare
Автор

I feel you, these union find dailies are brutal, I haven't had to do one in a long while.

YouTube_Staff
Автор

Thanks. With these hard tasks I often need your clean explanations.

ouchlock
Автор

Neetcode to the rescue, awesome explanation

krateskim
Автор

you are confused with both green and blue edges throughout the video but no worries i got the point man 👍

hemanth
Автор

also works with minimum spanning tree approach

EasterBunnyGaming
Автор

please keep uploading hard problems as well. Thank you

sharathkumar
Автор

Pretty neat solution. Also point to note, it doesnt look like your union find class implements path compression. It only looks like it does union find with rank

parashararamesh
Автор

funny how my algorithm teacher doesnt tell us to code but draw the edge but now when i do leetcode it show up...

GameFlife
Автор

16:09 Solution is not working unless I do bit wise or operation, this does not make any sense. Can anyone explain please ?

Rancha
Автор

I understand why we need to choose edges of type 3 first, but do the order type 3 edges is matter? For example we have 10 type 3 edges, we need to figure which type 3 edges to choose first to maximize the number of type 3 edges chosen.

lvisbl__
Автор

you werent uploading for so many days, everything alright ??

BurhanAijaz
Автор

class Solution:
def maxNumEdgesToRemove(self, n: int, e: List[List[int]]) -> int:
def h(z):
while
return z
b=[list(range(n+1)), [], []]
for t in range(3):
u=b[t]=b[0][:]
for v, w in ((v, w)for s, v, w in e if t+s==3):
u[v:=h(v)]=(w:=h(w))
u[0]+=(v!=w)
if t and u[0]!=n-1:return -1
return len(e)-2*(n-1)+b[0][0]

qulinxao
Автор

please code like you usually do, dont write the code before, that way we are more involved

BurhanAijaz
Автор

Neetcode can you explain Checking Existence of Edge Length Limited Paths problem 🥹, it's 1697 on leetcode

hypermeero