2192. All Ancestors of a Node in a Directed Acyclic Graph | Topological Sort | Merge Two Sorted List

  Рет қаралды 4,581

Aryan Mittal

Aryan Mittal

Күн бұрын

In this video, I'll talk about how to solve Leetcode 2192. All Ancestors of a Node in a Directed Acyclic Graph | Topological Sort | Merge Two Sorted List
Master Leetcode in 2024 - • How to start Leetcode ...
Topological Sort - • G-16 Topological Sort ...
Detect Cycle by Topological Sort in Directed Graph - • G-17 Detect Cycle in a...
Toposort Practice Problem - • Largest Color Value in...
Let's Connect:
📱Discord (Join Community) : / discord
📝Linkedin: / aryan-mittal-0077
📸 Instagram: / codewitharyanbhai
💻 Twitter - / aryan_mittal007
🤖 Github: github.com/ary...
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✨
✨ Hashtags ✨
#programming #Interviews #leetcode #faang #maang #datastructures #algorithms

Пікірлер: 14
@ARYANMITTAL
@ARYANMITTAL 2 ай бұрын
Master Leetcode in 2024 - kzbin.info/www/bejne/kJPOeGtjnsuhf80
@rajrajesh1669
@rajrajesh1669 2 ай бұрын
Bro, I forgot that problem you had a editorial which can be solved using multi bfs traversal. Can someone give me that problem name/link.
@nooob_coder
@nooob_coder 2 ай бұрын
thanks for all the efforts
@mohammedansil2302
@mohammedansil2302 2 ай бұрын
GREAT
@Vishalgupta-cs9cg
@Vishalgupta-cs9cg 2 ай бұрын
100% for your efforts bhai but fir bhi smz nhi aya .....hindi me daloge to jada understanding bethegi and grow bhi jada kr paoge bhai..e.g., love babbar and striver have same content but lovebabbar grow more becuase of his hindi language .
@The-coding-cracker28
@The-coding-cracker28 2 ай бұрын
Hi Aryan, I've been working on the same problem you discussed in your video about finding ancestors in a directed graph. Here’s the code I wrote to solve it using a topological sort approach. Could you please check it and let me know if there are any optimizations or improvements I can make? Thanks! class Solution { public: vector getAncestors(int n, vector& edges) { unordered_map mp; vector indegree(n, 0); for (const auto& edge : edges) { int u = edge[0]; int v = edge[1]; mp[u].push_back(v); indegree[v]++; } queue q; for (int i = 0; i < n; ++i) { if (indegree[i] == 0) { q.push(i); } } vector v(n); // Perform a topological sort while (!q.empty()) { int top = q.front(); q.pop(); for (int x : mp[top]) { indegree[x]--; if (indegree[x] == 0) { q.push(x); } v[x].insert(v[top].begin(), v[top].end()); v[x].insert(top); } } vector ans; for (const auto& x : v) { ans.push_back(vector(x.begin(), x.end())); } return ans; } };
@codencode5546
@codencode5546 2 ай бұрын
i didn't understand the 2 consq. sortedAncestors line
@mohit7717
@mohit7717 2 ай бұрын
Hello Hello Hello Aryan Good morning
@Munchen888
@Munchen888 2 ай бұрын
Dfs here is bad because it will be timeout (
@KADOfficial23
@KADOfficial23 2 ай бұрын
honestly, didnot understand anything.
@Vishalgupta-cs9cg
@Vishalgupta-cs9cg 2 ай бұрын
same hindi me smzane ki kosis kerta to ata bhi yrr
@limitless6189
@limitless6189 2 ай бұрын
explain in java. i am sure u r reach and subscribers will be doubled
@aayushyavajpayee4989
@aayushyavajpayee4989 2 ай бұрын
do not put such strong hints in video title, It spoils the question pretty quickly
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 306 М.
Girl, dig gently, or it will leak out soon.#funny #cute #comedy
00:17
Funny daughter's daily life
Рет қаралды 13 МЛН
АЗАРТНИК 4 |СЕЗОН 3 Серия
30:50
Inter Production
Рет қаралды 862 М.
哈莉奎因怎么变骷髅了#小丑 #shorts
00:19
好人小丑
Рет қаралды 34 МЛН
G-27. Shortest Path in Directed Acyclic Graph - Topological Sort
26:36
take U forward
Рет қаралды 219 М.
If I Wanted a Software Engineering Internship in 2025, I’d Do This
10:00
QLoRA-How to Fine-tune an LLM on a Single GPU (w/ Python Code)
36:58
Girl, dig gently, or it will leak out soon.#funny #cute #comedy
00:17
Funny daughter's daily life
Рет қаралды 13 МЛН