2092. Find All People With Secret | DSU | Disjoint Set Union | Graph | Google

  Рет қаралды 3,347

Aryan Mittal

Aryan Mittal

Күн бұрын

In this video, I'll talk about how to solve Leetcode 2092. Find All People With Secret | DSU | Disjoint Set Union | Graph | Google
Learn DSU - • Checking Existence of ...
Practice DSU - • 1579. Remove Max Numbe...
Checkout DSA-169 Series: • Aryan DSA-169 Series |...
100Days 100k Placements: • 100 Days 100K Placement
Let's Connect:
📝Linkedin: / aryan-mittal-0077
📸 Instagram: / ez.pz.dsa
📱Telegram : t.me/aryan_mittal_group
🤖 Github: github.com/aryan-0077
About Me:
I am Aryan Mittal - A Software Engineer in Goldman Sachs, Speaker, Creator & Educator. During my free time, I create programming education content on this channel & also how to use that to grow :)
✨ Timelines✨
0:00 - Problem Explanation
3:07 - Intuition by Explanation
6:30 - Extra Example
10:14 - Linking with Graph & DSU
13:11 - Suggested Video [Link in Description]
13:55 - DSU Dry Run
20:27 - Code Explanation & Complexity
✨ Hashtags ✨
#programming #Interviews #leetcode #faang #maang #datastructures #algorithms

Пікірлер: 19
@singhshek58
@singhshek58 5 ай бұрын
cigarette 🚬 😂
@user-qq5bb7bh5z
@user-qq5bb7bh5z 4 ай бұрын
believe me google asks lots of dsu based question Hope I knew it before and saw your videos explaining them earlier
@ARYANMITTAL
@ARYANMITTAL 5 ай бұрын
This is very frequently asked Google Question, do try it ⏰ . Learn DSU - kzbin.info/www/bejne/d6DWqGuJh9VqsJY Practice DSU - kzbin.info/www/bejne/q5yvqnl6oad5jZI
@ritishrai581
@ritishrai581 4 ай бұрын
I had a doubt regarding the tc of the bfs solution on the editorial of leetocode it says the atmax no of nodes in the queue can be N+M but i can't imagine how will that be the case I mean if we are visiting each node once it won't be pushed into the queue again right??? (by queue im referring to the pq based solution)
@aashirwadchauhan6634
@aashirwadchauhan6634 4 ай бұрын
bro can you provide the code once or your leetcode id ? I did code it up, but i don't know where i'm messing it up
@arpanrohilla1717
@arpanrohilla1717 4 ай бұрын
I made graph for every time and for every people who knew secret (I collected them in map ) I traversed the graph using bfs and added the traversed people in map and when it is traversed I cleared the graph, but I am not getting test cases accepted Pls can any body tell is there anything wrong with my approach
@pragatidas2910
@pragatidas2910 5 ай бұрын
ckraaat 😂😂😂
@sivalokesh3997
@sivalokesh3997 4 ай бұрын
I'm very interested to see all possible solutions even the video becomes 3hours+😊
@ARYANMITTAL
@ARYANMITTAL 4 ай бұрын
❤️❤️🫡😊
@39_jatinjain4
@39_jatinjain4 5 ай бұрын
why my sol is giving MLE-class Solution { public: static bool comp(const vector& a, const vector& b, const vector& ans) { if (a[2] == b[2]) { // Make a copy of ans if (ans[a[0]] == 1 || ans[a[1]] == 1) { return true; } return false; } return a[2] < b[2]; } vector findAllPeople(int n, vector& meet, int fp) { vector ans(n, 0); ans[fp] = ans[0] = 1; sort(meet.begin(), meet.end(), [&](const auto& a, const auto& b) { return comp(a, b, ans); }); for(auto it:meet){ if(ans[it[0]]==1 || ans[it[1]]==1){ ans[it[0]]=1; ans[it[1]]=1; } } vectorv; for(int i=0;i
@RudraPratapSinghTomar
@RudraPratapSinghTomar 4 ай бұрын
Secret ❌, Cigarette ✅
@harshal8781
@harshal8781 4 ай бұрын
secret ❌ cigarette✅
@6mahine_mein_google
@6mahine_mein_google 4 ай бұрын
at @17:20 while explaining you have not sorted the array properly [2,3,2] should have encountered first
@kkkkkkkkkk811
@kkkkkkkkkk811 5 ай бұрын
Bhaiya i am very weak in graphs..From where should i learn?
@rajrajesh1669
@rajrajesh1669 4 ай бұрын
Start from the linked list then trees then graph. Learn all these as a data structure like how they are visualized/structured/represented, once you are comfortable with the data structure then go for learning all kinds of Traversal techniques and then learn some classic algorithm for every data structure. You'll be in a better place...
@vypw3p634
@vypw3p634 4 ай бұрын
start from Striver graph playlist
@riyasailesh8878
@riyasailesh8878 4 ай бұрын
this channel has a good set of graph problems. I found it pretty useful.
@kannank4269
@kannank4269 4 ай бұрын
class DSU{ vector parent, rank, size; public: DSU(int N){ parent.resize(N + 1, 0); rank.resize(N + 1, 0); size.resize(N + 1, 1); for(int i = 0; i rank[ulp_v]){ parent[ulp_v] = ulp_u; } else{ parent[ulp_v] = ulp_u; rank[ulp_u]++; } } void union_by_size(int u, int v){ int ulp_u = findUPar(u); int ulp_v = findUPar(v); if(ulp_u == ulp_v){ return; } if(size[ulp_u] < size[ulp_v]){ parent[ulp_u] = ulp_v; size[ulp_v] += size[ulp_u]; } else{ parent[ulp_v] = ulp_u; size[ulp_u] += size[ulp_v]; } } void reset(int node){ parent[node] = node; } }; class Solution { public: vector findAllPeople(int n, vector& meetings, int firstperson) { auto comp = [&](vector a, vector b) -> bool{ if(a[2] == b[2]){ return true; } else{ return a[2] < b[2]; } }; sort(meetings.begin(), meetings.end(), comp); DSU ds(n + 1); ds.union_by_rank(0, firstperson); for(int i = 0; i < meetings.size(); ){ int curnt_time = meetings[i][2]; vector people; while(i < meetings.size() && meetings[i][2] == curnt_time){ ds.union_by_rank(meetings[i][0], meetings[i][1]); people.push_back(meetings[i][0]); people.push_back(meetings[i][1]); i++; } for(auto it : people){ if(ds.findUPar(it) != ds.findUPar(0)){ ds.reset(it); } } } vector ans; for(int i = 0; i < n; i++){ if(ds.findUPar(i) == ds.findUPar(0)){ ans.push_back(i); } } return ans; } }; if i directly give return true in the comparator function it throws an error saying accessing null pointer. But i change as aryan written in his code it is getting accepted why is it so ? please anyone help me
@vcr_colis9465
@vcr_colis9465 4 ай бұрын
allright_then_keep_your_secrets.gif
Red❤️+Green💚=
00:38
ISSEI / いっせい
Рет қаралды 76 МЛН
Despicable Me Fart Blaster
00:51
_vector_
Рет қаралды 23 МЛН
ОСКАР vs БАДАБУМЧИК БОЙ!  УВЕЗЛИ на СКОРОЙ!
13:45
Бадабумчик
Рет қаралды 6 МЛН
Scary Teacher 3D Nick Troll Squid Game in Brush Teeth White or Black Challenge #shorts
00:47
PAPMEM - Julho de 2024 - Recorrência nas provas da OBMEP
1:16:01
Instituto de Matemática Pura e Aplicada
Рет қаралды 119
Disjoint Set | UNION and FIND
26:43
Techdose
Рет қаралды 110 М.
Scientific Concepts You're Taught in School Which are Actually Wrong
14:36
Union Find in 5 minutes - Data Structures & Algorithms
5:46
Potato Coders
Рет қаралды 195 М.
❌ Don't Run Behind 500 LEETCODE Problems ❌ Focus on QPCD
8:31
Red❤️+Green💚=
00:38
ISSEI / いっせい
Рет қаралды 76 МЛН