面试场景
高频考察问题建模、边界条件与口头表达的清晰度。
常见误区
只背模板不解释为什么,容易在追问里失分。
练习策略
每轮练 3-5 题,固定复盘复杂度和可替代解法。
推荐练习顺序
克隆图
Clone Graph involves cloning a graph using DFS, focusing on graph traversal and neighbor management using hash tables.
课程表
Determine if all courses can be completed by analyzing prerequisite dependencies using indegree tracking and topological…
课程表 II
Solve the 'Course Schedule II' problem using graph indegree and topological ordering, utilizing DFS or BFS to find the c…
最小高度树
Identify all roots of a tree that produce minimum height using graph indegree analysis and topological trimming.
矩阵中的最长递增路径
Find the length of the longest increasing path in a matrix with given movement constraints using graph techniques.
重新安排行程
Reconstruct Itinerary requires building a valid travel route using all tickets once, starting from JFK with lexical orde…
除法求值
Compute the results of division queries from given equations using graph traversal and depth-first search efficiently.
省份数量
Solve Number of Provinces by scanning the adjacency matrix and launching DFS once per unvisited city component.
冗余连接
Identify and remove the redundant edge that causes a cycle in a graph starting as a tree.
冗余连接 II
Find and remove the redundant connection in a directed graph that was originally a rooted tree.
网络延迟时间
Find the minimum time for a signal to travel to all nodes in a directed graph or determine if it's impossible.
破解保险箱
The Cracking the Safe problem involves finding the shortest password sequence to unlock a safe using graph traversal and…
情侣牵手
This problem requires arranging couples sitting apart in a row with the minimum number of swaps using graph traversal an…
判断二分图
Determine whether an undirected graph can be split into two independent sets using DFS, BFS, or Union Find patterns.
K 站中转内最便宜的航班
Find the cheapest flight from a source to a destination with at most K stops using graph traversal techniques efficientl…
所有可能的路径
Find all paths in a directed acyclic graph (DAG) from source to target using depth-first search and backtracking.
找到最终的安全状态
Solve the problem of finding eventual safe states in a directed graph using depth-first search and topological sorting.
树中距离之和
The problem asks to compute the sum of distances between each node and all others in a tree structure using depth-first …
钥匙和房间
Determine if all rooms can be visited given keys distributed across a set of interconnected locked rooms using graph tra…
访问所有节点的最短路径
Solve the Shortest Path Visiting All Nodes problem by exploring dynamic programming, bit manipulation, and breadth-first…
喧闹和富有
Determine the quietest person richer than each individual using graph indegree analysis and topological ordering techniq…
细分图中的可到达节点
The Reachable Nodes In Subdivided Graph problem requires efficiently finding the reachable nodes using graph traversal a…
可能的二分法
Determine if a group of n people with mutual dislikes can be split into two non-conflicting groups using graph traversal…
猫和老鼠
Determine the outcome of a two-player Cat and Mouse game on a graph using topological ordering and memoized dynamic prog…
尽量减少恶意软件的传播
Identify which single infected node to remove to minimize total malware spread in a connected network graph efficiently.
尽量减少恶意软件的传播 II
Minimize Malware Spread II asks to minimize the spread of malware in a network of nodes by removing one infected node.
移除最多的同行或同列石头
Maximize the number of stones removed from a 2D plane using graph traversal and DFS.
等式方程的可满足性
Determine if it's possible to assign values to variables such that all equations are satisfied based on equality and ine…
找到小镇的法官
Find the Town Judge is an easy LeetCode problem that challenges you to identify a town judge from trust relationships us…
不邻接植花
In this problem, you are tasked with planting flowers in gardens with specific constraints based on graph traversal prin…
颜色交替的最短路径
Solve the shortest path problem with alternating edge colors using graph traversal and BFS.
查找集群内的关键连接
Find critical connections in a network of servers, ensuring efficient traversal using depth-first search and Tarjan's al…
项目管理
Sort items into groups while respecting dependencies using graph indegree tracking and topological ordering patterns eff…
你能从盒子里获得的最大糖果数
Collect maximum candies from boxes by exploring initially available boxes and using keys to unlock additional ones effic…
获取你好友已观看的视频
Find videos watched by friends up to a given level and return them sorted by frequency and alphabetically.
连通网络的操作次数
Determine the minimum number of operations required to connect all computers in a network with a limited number of cable…
阈值距离内邻居最少的城市
Find the city with the fewest neighbors within a given threshold distance using dynamic programming.
验证二叉树
Validate Binary Tree Nodes problem requires checking if a set of nodes forms a valid binary tree using graph traversal.
使网格图至少有一条有效路径的最小代价
Determine the minimum cost to create at least one valid path from the top-left to bottom-right in a directional grid.
T 秒后青蛙的位置
The problem asks for the probability that a frog reaches a target vertex after t seconds in a tree graph.
课程表 IV
Determine if one course is a prerequisite of another using graph indegree tracking and topological ordering efficiently.
重新规划路线
Reorder Routes to Make All Paths Lead to the City Zero involves reversing the direction of roads in a tree to ensure all…
找到最小生成树里的关键边和伪关键边
Identify critical and pseudo-critical edges in a weighted graph's minimum spanning tree using Union Find efficiently.
并行课程 II
Determine the minimum semesters to complete all courses with prerequisites using state transition dynamic programming an…
概率最大的路径
Find the path with the highest success probability in a graph from a start node to an end node, using edge probabilities…
可以到达所有点的最少点数目
Identify the minimum set of vertices in a directed acyclic graph from which all nodes are reachable efficiently using gr…
保证图可完全遍历
Maximize the number of edges that can be removed while keeping the graph fully traversable for both Alice and Bob.
连接所有点的最小费用
Min Cost to Connect All Points asks for the minimum cost to connect all points on a 2D plane, using manhattan distances …
奇怪的打印机 II
Solve Strange Printer II by building color dependencies from bounding rectangles and checking whether a topological orde…
最大网络秩
Calculate the maximum network rank of two cities by analyzing all city pairs using a graph-driven solution strategy effi…
矩阵转换后的排名
Compute a unique rank matrix using graph indegree with topological ordering, ensuring each element reflects its relative…
检查边长度限制的路径是否存在
Solve the problem of checking if there exists a path between two nodes under edge length constraints using efficient tec…
重构一棵树的方案数
Determine how many distinct rooted trees can be reconstructed from given node pairs using careful traversal and state tr…
猫和老鼠 II
Cat and Mouse II requires determining if the mouse can reach food before being caught using graph and topological orderi…
一个图中连通三元组的最小度数
Find the minimum degree of a connected trio in a graph using enumeration over nodes and edges.
统计点对的数目
Given a graph with nodes and edges, count pairs of nodes where the degree sum exceeds a given threshold for each query.
从第一个节点出发到最后一个节点的受限路径数
Solve the problem of finding the number of restricted paths in a weighted undirected graph, leveraging graph algorithms …
找出星型图的中心节点
Find the center node of a star graph, where one node connects to all others.
有向图中最大颜色值
Compute the maximum color frequency along any valid path in a directed graph using topological ordering and dynamic prog…
统计为蚁群构筑房间的不同顺序
Solve the problem of counting distinct ways to build rooms in an ant colony using dynamic programming and topological or…
规定时间内到达终点的最小花费
Minimize the travel cost in a graph while adhering to a time constraint using state transition dynamic programming.
寻找图中是否存在路径
Determine if a valid path exists between two vertices in a bi-directional graph using traversal techniques.
到达目的地的方案数
Find the number of ways to travel from intersection 0 to n - 1 in the shortest time, using a graph-based approach.
网络空闲的时刻
Calculate the time when the network becomes idle, factoring in message resending and the BFS traversal method.
到达目的地的第二短时间
Find the second minimum time to reach a destination using BFS while accounting for traffic signal delays in a graph trav…
并行课程 III
Solve Parallel Courses III by finding the minimum number of months to complete all courses using graph-based topological…
最大化一张图中的路径价值
Calculate the maximum path quality in a graph using backtracking and pruning to optimize node visits within time limits …
处理含限制条件的好友请求
Determine which friend requests can be accepted without violating direct or indirect restrictions using union-find logic…
找出知晓秘密的所有专家
Find all people who receive a secret through meetings using graph traversal with depth-first search efficiently and corr…
合法重新排列数对
Given pairs of numbers, find a valid arrangement where each pair follows a specific condition.
引爆最多的炸弹
Determine the maximum number of bombs that can be detonated by leveraging chain reactions using graph traversal and DFS …
从给定原材料中找到所有可以做出的菜
Determine all recipes you can prepare given initial supplies and ingredient dependencies, leveraging array scanning and …
参加会议的最多员工数
Determine the maximum employees to invite based on favorite adjacency constraints using graph indegree and topological o…
有向无环图中一个节点的所有祖先
Solve the All Ancestors of a Node in a Directed Acyclic Graph problem using graph traversal techniques like BFS, DFS, an…
包含要求路径的最小带权子图
Find the minimum weighted subgraph that connects three specified nodes in a directed graph with constraints.
节点序列的最大得分
Find the maximum score of a valid node sequence in an undirected graph with given node scores and edges.
相邻字符不同的最长路径
Find the longest path in a tree where adjacent nodes have different characters using graph DFS and topological reasoning…
道路的最大总重要性
Assign unique values to cities to maximize the total importance of all roads using greedy selection based on city connec…
到达角落需要移除障碍物的最小数目
Find the minimum obstacles to remove in a 2D grid to reach the bottom-right corner using BFS graph traversal techniques.
统计无向图中无法互相到达点对数
Calculate the total number of node pairs in an undirected graph that cannot reach each other using DFS, BFS, or Union Fi…
网格图中递增路径的数目
Solve Number of Increasing Paths in a Grid by turning cell comparisons into a DAG and counting paths with topological DP…
找到离给定两个节点最近的节点
Find the node that minimizes the maximum distance to two given nodes in a directed graph with one outgoing edge per node…
图中的最长环
The problem asks to find the longest cycle in a directed graph with specific edge constraints.
受限条件下可到达节点的数目
In the 'Reachable Nodes With Restrictions' problem, find the maximum reachable nodes from node 0 in a tree while avoidin…
边积分最高的节点
Determine the node with the highest edge score in a graph using hash table aggregation and careful index tracking.
给定条件下构造矩阵
Solve the matrix-building problem by using graph indegree and topological sorting to satisfy given row and column constr…
好路径的数目
Count all good paths in a tree by scanning node values and using hash maps to track valid connections efficiently.
树上最大得分和路径
Solve the 'Most Profitable Path in a Tree' problem using graph traversal and depth-first search techniques to maximize A…
到达首都的最少油耗
Calculate the minimum fuel needed for all city representatives to reach the capital using DFS on a tree graph efficientl…
两个城市间路径的最小分数
Find the minimum distance in a path connecting two cities using graph traversal strategies efficiently.
将节点分成尽可能多的组
Determine the maximum number of groups nodes can form in a graph using depth-first traversal without violating edge conn…
图中最大星和
Find the maximum star sum in a graph with specific node values and edges, using greedy algorithms to select the optimal …
添加边使所有节点度数都为偶数
Determine if it's possible to add at most two edges to make all node degrees even in an undirected graph.
在网格图中访问一个格子的最少时间
Compute the fastest path in a grid where each cell has a minimum time requirement using BFS and priority queue technique…
收集树中金币
The "Collect Coins in a Tree" problem requires traversing a tree to collect coins in the fewest steps while returning to…
图中的最短环
Find the shortest cycle in a bi-directional graph using BFS for optimal traversal.
设计可以求最短路径的图类
Implement a dynamic weighted directed graph with efficient shortest path queries and edge additions in real time.
最小化旅行的价格总和
Calculate the minimum total cost of multiple trips on a tree by selectively halving node prices using DFS frequency coun…
前往目标的最小代价
Find the minimum cost path between two points, using special roads or direct moves in a 2D space.
统计完全连通分量的数量
Determine the number of complete connected components in an undirected graph using efficient traversal techniques and gr…
修改图中的边权
Modify Graph Edge Weights is a graph problem where you adjust edge weights to match a target shortest path distance.
边权重均等查询
Find the minimum number of operations to equalize edge weights in a tree between given pairs of nodes.
可以到达每一个节点的最少边反转次数
This problem requires solving a graph traversal with edge reversals to ensure every node is reachable in a tree-like str…
有向图访问计数
Count Visited Nodes in a Directed Graph uses dynamic programming to solve graph traversal and node visitation counting e…
找到冠军 II
Identify the strongest team in a tournament DAG using graph-driven logic, ensuring correct handling of in-degree zero ch…
关闭分部的可行集合数目
Calculate all valid sets of branch closures while keeping remaining branches within maxDistance using bitmask and graph …
转换字符串的最小成本 I
This problem asks to calculate the minimum cost to convert a string from source to target using specific character trans…
转换字符串的最小成本 II
Compute the minimum cost to transform source into target using substring replacements with given costs efficiently using…
按距离统计房屋对数目 I
Determine the number of house pairs at each street distance using graph traversal and breadth-first search efficiently.
按距离统计房屋对数目 II
Count the Number of Houses at a Certain Distance II is a graph problem that requires efficient pair counting with an add…
带权图里旅途的最小代价
Find the minimum cost walk in a weighted graph using array and bit manipulation techniques for efficient path calculatio…
访问消失节点的最少时间
Determine the minimum time to visit each node in a disappearing-node graph using arrays, graphs, and priority queues eff…
最短路径中的边
Use two Dijkstra runs to mark exactly which edges can appear on at least one shortest path from 0 to n - 1.
合并两棵树后的最小直径
Calculate the minimum diameter after merging two trees by strategically connecting nodes to minimize the longest path in…
标记所有节点需要的时间
Calculate the time taken to mark all nodes in a tree, starting from any node with time t=0.
新增道路查询后的最短距离 I
Solve shortest paths dynamically in a growing graph using BFS, updating distances efficiently after each road addition q…
新增道路查询后的最短距离 II
The problem involves calculating the shortest path from city 0 to city n-1 after each road addition, leveraging greedy c…
穿越网格图的安全路径
Determine if you can safely traverse a binary grid from top-left to bottom-right using limited health points.
移除可疑的方法
Remove suspicious methods in a project that are invoked directly or indirectly from a buggy method using graph traversal…
构造符合图结构的二维矩阵
This problem challenges you to construct a 2D grid from an undirected graph using a given set of edges.
到达最后一个房间的最少时间 I
Find Minimum Time to Reach Last Room I challenges you to determine the minimum time to travel in a dungeon with a grid l…
到达最后一个房间的最少时间 II
Calculate the minimum time to reach the last room in a grid with alternating move times using array and graph patterns.
使两个整数相等的数位操作
Transform n into m using allowed digit operations without creating primes, applying math and graph strategies efficientl…
两天自由外汇交易后的最大货币数
Compute the maximum currency amount after two days using graph traversal and depth-first search for optimal conversions.
图的最大边权的最小值
Minimize the maximum edge weight in a graph after removing certain edges while ensuring node reachability.
最短公共超序列的字母出现频率
Compute all unique shortest common supersequences of given words using graph indegree tracking and topological ordering …
属性图
Find the number of connected components in an undirected graph formed by properties arrays, using array scanning and has…
单位转换 I
Solve the unit conversion problem by using graph traversal to compute equivalent unit amounts.
有向无环图中合法拓扑排序的最大利润
Solve the Maximum Profit from Valid Topological Order in DAG problem using graph indegree and topological sorting with d…
针对图的路径存在性查询 I
Determine if paths exist between nodes using array scanning and hash lookups for efficient component checks in graphs.
针对图的路径存在性查询 II
Solve path existence queries in a graph using binary search on the answer space, focusing on sorted nodes and maximum di…
K 条边路径的最大边权和
Determine the maximum sum of edge weights for a k-edge path in a DAG using state transition dynamic programming efficien…
图中边值的最大和
Maximize the sum of edge values in a connected graph by assigning unique node values and optimizing edge products.
所有人渡河所需的最短时间
Find the minimum time to transport individuals across a river with dynamic environmental conditions and boat capacity.
升级后最大生成树稳定性
Maximizing the stability of a spanning tree with upgrades requires careful optimization of edge strengths using binary s…
有向图中到达终点的最少时间
The problem involves finding the minimum time to reach the destination in a directed graph with time-dependent edges.
电网维护
Determine which power stations remain connected after maintenance using array scanning and hash lookups to track compone…
包含 K 个连通分量需要的最小时间
Find the minimum time to remove edges such that a graph with n nodes has at least k connected components.
最小化连通分量的最大成本
Minimize Maximum Component Cost leverages binary search over edge weights to optimize the cost of graph components after…
图中的最长回文路径
Find the longest path in a graph that forms a palindrome using state transition dynamic programming and bitmask techniqu…
恢复网络路径
Find the maximum recovery cost of valid paths in a directed acyclic graph where some nodes are offline.