题库chevron_right分类chevron_right拓扑排序
low_priority

拓扑排序

28 道题目
简单: 0中等: 10困难: 18

拓扑排序 是技术面试里最常出现的能力维度之一。建议先掌握基础题型的边界处理,再逐步过渡到模式识别和复杂度 trade-off。

面试场景

高频考察问题建模、边界条件与口头表达的清晰度。

常见误区

只背模板不解释为什么,容易在追问里失分。

练习策略

每轮练 3-5 题,固定复盘复杂度和可替代解法。

推荐练习顺序

#题目难度
207

课程表

Determine if all courses can be completed by analyzing prerequisite dependencies using indegree tracking and topological…

中等
210

课程表 II

Solve the 'Course Schedule II' problem using graph indegree and topological ordering, utilizing DFS or BFS to find the c…

中等
310

最小高度树

Identify all roots of a tree that produce minimum height using graph indegree analysis and topological trimming.

中等
329

矩阵中的最长递增路径

Find the length of the longest increasing path in a matrix with given movement constraints using graph techniques.

困难
802

找到最终的安全状态

Solve the problem of finding eventual safe states in a directed graph using depth-first search and topological sorting.

中等
851

喧闹和富有

Determine the quietest person richer than each individual using graph indegree analysis and topological ordering techniq…

中等
913

猫和老鼠

Determine the outcome of a two-player Cat and Mouse game on a graph using topological ordering and memoized dynamic prog…

困难
1203

项目管理

Sort items into groups while respecting dependencies using graph indegree tracking and topological ordering patterns eff…

困难
1462

课程表 IV

Determine if one course is a prerequisite of another using graph indegree tracking and topological ordering efficiently.

中等
1591

奇怪的打印机 II

Solve Strange Printer II by building color dependencies from bounding rectangles and checking whether a topological orde…

困难
1632

矩阵转换后的排名

Compute a unique rank matrix using graph indegree with topological ordering, ensuring each element reflects its relative…

困难
1728

猫和老鼠 II

Cat and Mouse II requires determining if the mouse can reach food before being caught using graph and topological orderi…

困难
1786

从第一个节点出发到最后一个节点的受限路径数

Solve the problem of finding the number of restricted paths in a weighted undirected graph, leveraging graph algorithms …

中等
1857

有向图中最大颜色值

Compute the maximum color frequency along any valid path in a directed graph using topological ordering and dynamic prog…

困难
1916

统计为蚁群构筑房间的不同顺序

Solve the problem of counting distinct ways to build rooms in an ant colony using dynamic programming and topological or…

困难
1976

到达目的地的方案数

Find the number of ways to travel from intersection 0 to n - 1 in the shortest time, using a graph-based approach.

中等
2050

并行课程 III

Solve Parallel Courses III by finding the minimum number of months to complete all courses using graph-based topological…

困难
2115

从给定原材料中找到所有可以做出的菜

Determine all recipes you can prepare given initial supplies and ingredient dependencies, leveraging array scanning and …

中等
2127

参加会议的最多员工数

Determine the maximum employees to invite based on favorite adjacency constraints using graph indegree and topological o…

困难
2192

有向无环图中一个节点的所有祖先

Solve the All Ancestors of a Node in a Directed Acyclic Graph problem using graph traversal techniques like BFS, DFS, an…

中等
2246

相邻字符不同的最长路径

Find the longest path in a tree where adjacent nodes have different characters using graph DFS and topological reasoning…

困难
2328

网格图中递增路径的数目

Solve Number of Increasing Paths in a Grid by turning cell comparisons into a DAG and counting paths with topological DP…

困难
2360

图中的最长环

The problem asks to find the longest cycle in a directed graph with specific edge constraints.

困难
2392

给定条件下构造矩阵

Solve the matrix-building problem by using graph indegree and topological sorting to satisfy given row and column constr…

困难
2603

收集树中金币

The "Collect Coins in a Tree" problem requires traversing a tree to collect coins in the fewest steps while returning to…

困难
3435

最短公共超序列的字母出现频率

Compute all unique shortest common supersequences of given words using graph indegree tracking and topological ordering …

困难
3530

有向无环图中合法拓扑排序的最大利润

Solve the Maximum Profit from Valid Topological Order in DAG problem using graph indegree and topological sorting with d…

困难
3620

恢复网络路径

Find the maximum recovery cost of valid paths in a directed acyclic graph where some nodes are offline.

困难

关联高频模式

LeetCode 拓扑排序题型题解:28题训练路线