Problem Name:
2192. All Ancestors of a Node in a Directed Acyclic Graph
Problem Statement:
You are given a positive integer n representing the number of nodes of a Directed Acyclic Graph (DAG). The nodes are numbered from 0 to n - 1 (inclusive).
You are also given a 2D integer array edges, where edges[i] = [fromi, toi] denotes that there is a unidirectional edge from fromi to toi in the graph.
Return a list answer, where answer[i] is the list of ancestors of the ith node, sorted in ascending order.
A node u is an ancestor of another node v if u can reach v via a set of edges.
Problem link:
leetcode.com/problems/all-anc...
Java Plus DSA Placement Course Playlist:
• Java and DSA Course Pl...
Java Plus DSA Sheet:
docs.google.com/spreadsheets/...
Notes:
github.com/Tiwarishashwat/Jav...
Telegram Link:
shashwattiwari.page.link/tele...
Ultimate Recursion Series Playlist:
• Recursion and Backtrac...
Instagram Handle: (@shashwat_tiwari_st)
shashwattiwari.page.link/shas...
Samsung Interview Experience:
• I cracked Samsung | SR...
Company Tags:
Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe | Samsung
Timestamp:
0:00 - Introduction
1:26 - Problem Explanation
4:48 - DFS Approach - 1 Explanation
13:03 - DFS Live Coding
20:35 - DFS Shortcoming
21:25 - Toposort Intro
23:13 - Using toposort in this question?
24:46 - finding ancestors using toposort
28:34 - toposort explanation
35:01 - Code with toposort
#ShashwatTiwari #coding #problemsolving
25 июл 2024