Accounts Merge - Leetcode 721 - Python

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


0:00 - Read the problem
0:50 - Drawing Explanation
10:10 - Coding Explanation

leetcode 721

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

Definitely not a medium problem. Should be a hard problem in my opinion...

guilhermezardo
Автор

Interesting solution to use the account index as the nodes being joined in the graph.
I too used a Union-Find solution but used the email strings as the nodes instead. Using the index, it is pretty trivial to find the name. In my solution, I needed a map from parent -> name.
Part of the problem is that Union-Find provides as output a non-useful child -> parent tree, which you need to invert into parent -> children.
The last loop can be done using list comprehension in one line.

DavidDLee
Автор

I'm just happy that I'm able to at least understand the terminologies used in this video 😅

technophile_
Автор

Wait what was the time and space complexity?

huzayfasabri
Автор

What a coincidence, I was working on this one. Are you doing grind75 problems now??

atreides
Автор

Your videos are great and you explain everything very well. I am not sure if that is just me, but oftentimes I am confused by your variable names. Great example is 14:31 you turned "email" variable name to "e" that with "i" emailToAcc (why not simply emailToAccount?). Maybe it is just me, but that makes it more difficult in my opion to follow along and read the solution.

kacpermodkowski
Автор

The neatness of ur code makes u neetcode😊

krishnasharma
Автор

10:52 I don't understand how union find operations take only constant time? Worst case would be log n isn't it?

subikeshps
Автор

please make solutions for leetcode weekly contests here onwards if possible please, your explanations are very easy and understandable. No one on YouTube explains better than you.

So I can learn to solve weekly problems

anishkarthik
Автор

Solved this problem like 3 days ago. It was a pain in the butt to get my head around using dfs with two different references.

kyoungjunhan
Автор

Bro make videos on leetcode contests too

sumitsharma
Автор

It would be better if u link ur union find explanation video in description itself very hectic to find that in ur old library😢

devenderbhatt
Автор

Love your vids bro. Is the time complexity O(NKlogK) where N accounts, K max-emails in an account, as for the DFS solution?

pacomarmolejo
Автор

Cann't we just use DFS instead of using disjoint sets. ? Whats the efficiency in using disjoint sets, anyways we have to traverse all connected components.

ayushbhardwaj
Автор

Hi man! Move your content and thank you very much for helping us! Would love if u could also make playlists here of "Easy", "Medium" and "Hard" related to how the leetcode problems solved in the videos are.

Daniel-domh
Автор

please make solutions for leetcode weekly contests

subhaspaul
Автор

This is the most crack head of crack head problems that I've run into in my humble opinion. Just because it's commonly asked in Big Tech interviews doesn't mean it should be ranked as a medium, more so a very common hard problem.

les_grossman
Автор

@NeetCode what is the time&space complexity ?

LiadMotorin
Автор

The path compression of find() in your code is not actually compressing path, here is the one that actually compress:
def find(self, node):
# Path Compression
parentIdx = self.parents[node]
while parentIdx != self.parents[parentIdx]:
parentIdx = self.parents[parentIdx]
self.parents[node] = parentIdx
 return parentIdx

alentino_woo
join shbcf.ru