Topological-Sort
Topological Sort
·3 mins
Algorithm
Graph
Topological-Sort
Kahn
Ordering, cycle detection, dependency unlocking, and graph propagation
LeetCode 2328: Number of Increasing Paths in a Grid
·2 mins
LeetCode
Hard
Dynamic-Programming
Grid-Dp
Memoization
Topological-Sort
Matrix
LeetCode 2328 note: strictly increasing means no cycles; dp[cell] = 1 + Σ dp[larger neighbors], processed from largest to smallest value (or by memoized DFS), summed over all cells
LeetCode 2392: Build a Matrix With Conditions
·2 mins
LeetCode
Hard
Graph
Topological-Sort
Matrix
LeetCode 2392 note: row and column conditions are independent, so run one topological sort for each; put x at its row and column positions, and return an empty matrix if either has a cycle
LeetCode 2603: Collect Coins in a Tree
·4 mins
LeetCode
Hard
Tree
Graph
Topological-Sort
LeetCode 2603 note: trim coin-free leaves, trim exactly two more layers, and walk each remaining edge twice
LeetCode 1059: All Paths from Source Lead to Destination
·2 mins
LeetCode
Medium
Graph
Topological-Sort
LeetCode 1059 note: trim outdegrees backward from the destination; a node is safe only when every outgoing edge leads to a safe node, and the destination itself must have no outgoing edges
LeetCode 269: Alien Dictionary
·3 mins
LeetCode
Hard
Graph
Topological-Sort
LeetCode note for Alien Dictionary, rebuilt from the original learning note
LeetCode 851: Loud and Rich
·2 mins
LeetCode
Medium
Graph
Topological-Sort
LeetCode note for Loud and Rich, rebuilt from the original learning note
LeetCode 802: Find Eventual Safe States
·3 mins
LeetCode
Medium
Graph
Topological-Sort
LeetCode note for Find Eventual Safe States, rebuilt from the original learning note
LeetCode 1203: Sort Items by Groups Respecting Dependencies
·3 mins
LeetCode
Hard
Graph
Topological-Sort
LeetCode note for Sort Items by Groups Respecting Dependencies, rebuilt from the original learning note
LeetCode 310: Minimum Height Trees
·3 mins
LeetCode
Medium
Graph
Topological-Sort
LeetCode note for Minimum Height Trees, rebuilt from the original learning note
LeetCode 2115: Find All Possible Recipes from Given Supplies
·3 mins
LeetCode
Medium
Graph
Topological-Sort
LeetCode note for Find All Possible Recipes from Given Supplies, rebuilt from the original learning note
LeetCode 2192: All Ancestors of a Node in a DAG
·3 mins
LeetCode
Medium
Graph
Topological-Sort
LeetCode note for All Ancestors of a Node in a DAG, rebuilt from the original learning note