Topological Sort LeetCode Problems: All 32,
With Python Solutions

Every problem in this library that LeetCode tags Topological Sort. 24 of them carry a complete Python solution, a worked example and the time and space complexity of the approach.

Easy
0
Medium
14
Hard
18
1 pattern

How Topological Sort problems are solved

A tag names the subject, not the method. These pattern hubs cover the techniques that actually solve Topological Sort problems — each one explains the approach, gives a Python template and states its complexity.

Eyes only

When the Topological Sort problem arrives live.

In the live round, Stealth Interview reads the problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer says. It's a desktop app for macOS and Windows, invisible to screen sharing.

Topological Sort problems by difficulty

Problems with a complete Python solution are listed first, then by ascending problem number.

Medium (14)

Medium problems
No.Problem
0207Course Schedule
0210Course Schedule II
0310Minimum Height Trees
0802Find Eventual Safe States
0851Loud and Rich
1462Course Schedule IV
1786Number of Restricted Paths From First to Last Node
1976Number of Ways to Arrive at Destination
2115Find All Possible Recipes from Given Supplies
2192All Ancestors of a Node in a Directed Acyclic Graph
0444Sequence ReconstructionPremium
1059All Paths from Source Lead to DestinationPremium
1136Parallel CoursesPremium
1245Tree DiameterPremium

Hard (18)

Hard problems
No.Problem
0329Longest Increasing Path in a Matrix
0913Cat and Mouse
1203Sort Items by Groups Respecting Dependencies
1632Rank Transform of a Matrix
1728Cat and Mouse II
1857Largest Color Value in a Directed Graph
1916Count Ways to Build Rooms in an Ant Colony
2050Parallel Courses III
2127Maximum Employees to Be Invited to a Meeting
2246Longest Path With Different Adjacent Characters
2328Number of Increasing Paths in a Grid
2360Longest Cycle in a Graph
2392Build a Matrix With Conditions
2603Collect Coins in a Tree
0269Alien DictionaryPremium
0631Design Excel Sum FormulaPremium
1591Strange Printer II
2371Minimize Maximum Value in a GridPremium