面试场景
高频考察问题建模、边界条件与口头表达的清晰度。
常见误区
只背模板不解释为什么,容易在追问里失分。
练习策略
每轮练 3-5 题,固定复盘复杂度和可替代解法。
推荐练习顺序
相同的树
Check whether two binary trees are identical by comparing structure and node values using DFS or BFS traversal strategie…
对称二叉树
Determine if a binary tree is symmetric by comparing left and right subtrees using DFS or BFS traversal techniques effic…
二叉树的层序遍历
Perform a level order traversal on a binary tree using BFS to return node values level by level.
二叉树的锯齿形层序遍历
Traverse a binary tree in zigzag level order, alternating directions at each depth using BFS and state tracking techniqu…
二叉树的最大深度
Find the maximum depth of a binary tree using traversal techniques to track the longest path from root to leaf.
二叉树的层序遍历 II
Return a bottom-up level order traversal of a binary tree, processing nodes left to right while tracking each level accu…
二叉树的最小深度
Find the minimum depth of a binary tree, which is the shortest path from the root node to the nearest leaf node.
路径总和
Determine if a binary tree has a root-to-leaf path where the sum of node values equals a given target sum, using DFS or …
填充每个节点的下一个右侧节点指针
Connect each node across every level by reusing established next links to traverse a perfect binary tree without extra q…
填充每个节点的下一个右侧节点指针 II
Populate each next pointer in a binary tree to its immediate right node, handling nulls and uneven levels efficiently us…
单词接龙 II
Find all shortest transformation sequences from beginWord to endWord using a dictionary, leveraging backtracking search …
单词接龙
Find the shortest transformation sequence from a start word to an end word, with each word in the sequence differing by …
被围绕的区域
Transform the matrix in-place by marking regions surrounded by 'X' as 'X', while keeping border-adjacent 'O's intact.
克隆图
Clone Graph involves cloning a graph using DFS, focusing on graph traversal and neighbor management using hash tables.
二叉树的右视图
The Binary Tree Right Side View problem asks you to return the visible nodes from the right side of a binary tree, trave…
岛屿数量
Count the number of distinct islands in a binary grid using array traversal combined with depth-first search exploration…
课程表
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…
翻转二叉树
Invert Binary Tree swaps every node's left and right children using tree traversal, with recursive DFS or iterative BFS …
完全平方数
Perfect Squares asks for the least number of perfect squares summing to a given integer n using dynamic programming or B…
二叉树的序列化与反序列化
This problem asks to serialize and deserialize a binary tree, requiring an efficient approach to handle traversal and st…
删除无效的括号
Remove the minimum number of invalid parentheses to generate all possible valid strings efficiently using backtracking a…
最小高度树
Identify all roots of a tree that produce minimum height using graph indegree analysis and topological trimming.
零钱兑换
Find the minimum number of coins needed to reach a target amount using dynamic programming state transitions efficiently…
矩阵中的最长递增路径
Find the length of the longest increasing path in a matrix with given movement constraints using graph techniques.
水壶问题
Determine if two jugs with given capacities can measure an exact target amount using math and DFS strategies efficiently…
除法求值
Compute the results of division queries from given equations using graph traversal and depth-first search efficiently.
左叶子之和
Compute the total of all left leaves in a binary tree using precise traversal and state tracking techniques for correctn…
接雨水 II
Solve Trapping Rain Water II using breadth-first search and priority queues for efficient water trapping in a matrix.
太平洋大西洋水流问题
Find all cells on an island where water can flow to both the Pacific and Atlantic oceans using DFS or BFS.
N 叉树的层序遍历
Perform a level order traversal on an n-ary tree, capturing nodes by depth using breadth-first search with careful state…
最小基因变化
Determine the minimum number of single-character gene mutations to reach the target gene using BFS and a hash table look…
序列化和反序列化二叉搜索树
Design an algorithm to serialize and deserialize a binary search tree with efficient traversal and state tracking.
岛屿的周长
Determine the perimeter of an island in a grid of land and water cells using DFS or BFS.
祖玛游戏
The Zuma Game involves clearing balls from the board using a limited hand, applying dynamic programming and state transi…
找树左下角的值
Find the leftmost value in the last row of a binary tree using efficient traversal strategies.
自由之路
Determine the minimum rotations and button presses to spell a keyword on a circular dial using state transition dynamic …
在每个树行中找最大值
Find the largest value in each row of a binary tree using depth-first or breadth-first search techniques.
扫雷游戏
Solve the Minesweeper game by updating revealed squares and handling clicks with Depth-First Search and Array manipulati…
二叉搜索树的最小绝对差
Find the minimum absolute difference between values of any two nodes in a BST using tree traversal and careful state tra…
01 矩阵
The '01 Matrix' problem challenges you to find the nearest zero for each cell in a binary matrix using dynamic programmi…
省份数量
Solve Number of Provinces by scanning the adjacency matrix and launching DFS once per unvisited city component.
N 叉树的最大深度
Find the maximum depth of an N-ary tree, leveraging tree traversal techniques and state tracking.
合并二叉树
Merge Two Binary Trees requires combining nodes by summing overlapping values while preserving non-null nodes from eithe…
在二叉树中增加一行
The problem requires adding a row of nodes to a binary tree at a specified depth.
二叉树的层平均值
Calculate the average value of nodes on each level of a binary tree using traversal and state tracking.
两数之和 IV - 输入二叉搜索树
Determine if a binary search tree contains two nodes whose values sum to a target using efficient traversal and state tr…
输出二叉树
Print Binary Tree requires arranging a binary tree into a visually structured matrix using precise traversal and positio…
二叉树最大宽度
Determine the maximum width of a binary tree by calculating the width of each level and considering the positions of the…
灯泡开关 Ⅱ
Compute all unique bulb configurations after a fixed number of presses using math and bit manipulation efficiently.
为高尔夫比赛砍树
Determine the minimum steps to cut all trees in a forest matrix in ascending height order using BFS traversal and priori…
冗余连接
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.
员工的重要性
Calculate an employee's total importance including all direct and indirect subordinates using array scanning and hash lo…
岛屿的最大面积
Find the largest connected land area in a binary grid using array traversal and depth-first search efficiently.
账户合并
Merge accounts by connecting emails and returning each user's sorted email list using array scanning and hash lookup eff…
图像渲染
Flood Fill is an array and DFS problem where you change connected pixels to a target color efficiently using recursion o…
网络延迟时间
Find the minimum time for a signal to travel to all nodes in a directed graph or determine if it's impossible.
隔离病毒
Contain Virus involves using array-based Depth-First Search to contain viral spread by building walls around infected re…
打开转盘锁
Solve the Open the Lock problem using array scanning plus hash lookup to efficiently find the shortest unlock sequence.
金字塔转换矩阵
The Pyramid Transition Matrix problem requires determining whether a pyramid can be formed with given blocks and valid p…
情侣牵手
This problem requires arranging couples sitting apart in a row with the minimum number of swaps using graph traversal an…
滑动谜题
Determine the minimum moves to solve a 2x3 sliding puzzle using BFS and state transition dynamic programming techniques …
水位上升的泳池中游泳
Solve the problem of swimming through a grid of rising water with a binary search on the valid answer space.
二叉搜索树节点最小距离
Find the minimum difference between values of two different nodes in a Binary Search Tree using tree traversal and state…
判断二分图
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.
公交路线
Bus Routes is solved by BFS over buses and stops, using stop-to-route hashing to avoid expensive repeated route scans.
最大人工岛
Calculate the largest island size by converting at most one zero in a binary grid using array and DFS techniques efficie…
相似字符串组
Determine the number of connected groups of similar strings by swapping at most two letters using array scanning and has…
钥匙和房间
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…
相似度为 K 的字符串
K-Similar Strings involves finding the minimal number of swaps to transform one string into another through character sw…
二叉树中所有距离为 K 的结点
Find all nodes at distance K from a target node in a binary tree using various tree traversal techniques.
获取所有钥匙的最短路径
Find the minimum steps to collect all keys in a grid using BFS and bitmasking, handling locks efficiently.
具有所有最深节点的最小子树
Find the smallest subtree that contains all the deepest nodes in a binary tree.
可能的二分法
Determine if a group of n people with mutual dislikes can be split into two non-conflicting groups using graph traversal…
蛇梯棋
Solve the Snakes and Ladders problem using a BFS strategy to efficiently navigate the board and reach the final square.
完全二叉树插入器
Implement a data structure to insert nodes into a complete binary tree while preserving its completeness efficiently.
尽量减少恶意软件的传播
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.
最短的桥
Find the minimum flips to connect two separate islands in a binary matrix using Array and DFS techniques efficiently.
二叉树的完全性检验
Determine if a binary tree is complete by verifying its node structure and leftmost placement in the last level.
由斜杠划分区域
Determine the number of regions in a grid divided by slashes using array scanning and union-find techniques efficiently.
单值二叉树
Determine if a binary tree is uni-valued using traversal and state tracking techniques.
连续差相同的数字
Generate all n-digit numbers where consecutive digits differ by k using efficient backtracking and BFS techniques.
二叉树的垂序遍历
Perform a vertical order traversal of a binary tree, sorting nodes by their values within columns.
二叉树的堂兄弟节点
Determine if two nodes in a binary tree are cousins by leveraging binary-tree traversal and state tracking.
腐烂的橘子
Given a grid with fresh and rotten oranges, return the minimum time for all oranges to rot or -1 if impossible.
飞地的数量
This problem involves finding the number of land cells that cannot reach the boundary in a grid using DFS and array mani…
边界着色
Given a grid and a starting cell, color all border cells of the connected component using DFS while preserving interior …
逃离大迷宫
The 'Escape a Large Maze' problem involves navigating a massive grid with blocked squares and finding if a target can be…
不邻接植花
In this problem, you are tasked with planting flowers in gardens with specific constraints based on graph traversal prin…
二进制矩阵中的最短路径
Find the shortest clear path in a binary matrix using BFS, carefully handling obstacles and diagonal movements for effic…
花括号展开 II
Solve Brace Expansion II efficiently by using stack-based state management to generate all unique combinations of nested…
最深叶节点的最近公共祖先
Find the lowest common ancestor of the deepest leaves in a binary tree using efficient traversal and state tracking tech…
颜色交替的最短路径
Solve the shortest path problem with alternating edge colors using graph traversal and BFS.
最大层内元素和
Find the level of a binary tree where the sum of its nodes is maximal, with an emphasis on binary-tree traversal.
地图分析
Find the farthest water cell from land in a grid and return the Manhattan distance using state transition dynamic progra…
交换字符串中的元素
Find the lexicographically smallest string by swapping characters in given pairs of indices.
项目管理
Sort items into groups while respecting dependencies using graph indegree tracking and topological ordering patterns eff…
穿过迷宫的最少移动次数
Find the minimum moves for a 2-cell snake to reach the bottom-right corner using rotations and BFS traversal in a grid.
统计封闭岛屿的数目
Count the number of closed islands in a 2D grid using array traversal and depth-first search efficiently.
在受污染的二叉树中查找元素
Recover values in a contaminated binary tree and efficiently check for existence using traversal and state tracking tech…
推箱子
Solve the minimum moves to push a box to its target using BFS and priority handling in a grid-based warehouse layout eff…
统计参与通信的服务器
Count Servers that Communicate involves identifying servers in a grid that can communicate based on row or column connec…
转化为全零矩阵的最少反转次数
Compute the minimum flips to convert a binary matrix to zero by toggling cells and neighbors using array scanning plus h…
网格中的最短路径
Find the shortest path in a grid with obstacles, allowing the elimination of up to k obstacles using BFS.
你能从盒子里获得的最大糖果数
Collect maximum candies from boxes by exploring initially available boxes and using keys to unlock additional ones effic…
层数最深叶子节点的和
Find the sum of the deepest leaves in a binary tree by using tree traversal and state tracking techniques.
跳跃游戏 III
Jump Game III challenges you to determine if you can reach any zero in an array using jumps defined by array values, tes…
获取你好友已观看的视频
Find videos watched by friends up to a given level and return them sorted by frequency and alphabetically.
祖父节点值为偶数的节点和
This problem involves calculating the sum of nodes with an even-valued grandparent in a binary tree.
连通网络的操作次数
Determine the minimum number of operations required to connect all computers in a network with a limited number of cable…
跳跃游戏 IV
Jump Game IV requires minimizing steps to reach the last index using jumps across equal values and neighbors efficiently…
验证二叉树
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.
通知所有员工所需的时间
Calculate the time needed for the head of a company to inform all employees using tree traversal techniques.
T 秒后青蛙的位置
The problem asks for the probability that a frog reaches a target vertex after t seconds in a tree graph.
找出克隆二叉树中的相同节点
Find the corresponding node in a cloned binary tree using binary-tree traversal and state tracking.
检查网格中是否存在有效路径
Check if there is a valid path from the upper-left to the bottom-right corner of a grid using depth-first search.
收集树上所有苹果的最少时间
Minimize the time spent to collect all apples in a tree, considering traversal and state tracking with binary tree techn…
统计二叉树中好节点的数目
Count Good Nodes in Binary Tree identifies nodes exceeding all previous values along their path using DFS traversal tech…
二叉树中的伪回文路径
Count all root-to-leaf paths in a binary tree that can be rearranged to form a palindrome using bitwise state tracking.
课程表 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…
树节点的第 K 个祖先
Find the kth ancestor of any node in a tree using efficient binary-tree traversal and dynamic state tracking methods.
子树中标签相同的节点数
Compute the number of nodes in each subtree sharing the same label using DFS with hash table aggregation efficiently.
二维网格图中探测环
Detect cycles in a 2D character grid using DFS while carefully tracking parent cells to avoid invalid revisits.
使陆地分离的最少天数
Find the minimum number of days to disconnect an island in a grid using depth-first search.
奇偶树
Determine if a binary tree meets Even-Odd rules by checking value parity and strict ordering at each level efficiently.
执行操作后字典序最小的字符串
Optimize a string through rotations and additions to get the lexicographically smallest possible result using string man…
最小体力消耗路径
Find the minimum effort required to travel from the top-left to the bottom-right of a grid, considering height differenc…
到家的最少跳跃次数
Find the minimum number of jumps needed to reach a target position while avoiding forbidden positions.
地图中的最高点
Solve the Map of Highest Peak problem using breadth-first search to assign heights based on proximity to water cells.
统计子岛屿
Identify and count all islands in grid2 that are fully contained within islands of grid1 using DFS traversal efficiently…
迷宫中离入口最近的出口
Find the shortest path from the maze entrance to the nearest border exit using BFS over a 2D array matrix efficiently.
你能穿过矩阵的最后一天
Find the last day to walk from top to bottom in a flooded matrix by using binary search and graph traversal techniques.
寻找图中是否存在路径
Determine if a valid path exists between two vertices in a bi-directional graph using traversal techniques.
找到所有的农场组
Identify all rectangular farmland groups in a binary matrix using array traversal and depth-first search efficiently.
树上的操作
Design a tree data structure that allows locking, unlocking, and upgrading nodes with user-specific actions.
网络空闲的时刻
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…
转化数字的最小运算数
Determine the minimum operations needed to convert a number using array elements with addition, subtraction, or XOR oper…
找出知晓秘密的所有专家
Find all people who receive a secret through meetings using graph traversal with depth-first search efficiently and corr…
引爆最多的炸弹
Determine the maximum number of bombs that can be detonated by leveraging chain reactions using graph traversal and DFS …
价格范围内最高排名的 K 样物品
Use BFS to rank reachable shop items by distance, price, row, and column, then return the best k coordinates.
有向无环图中一个节点的所有祖先
Solve the All Ancestors of a Node in a Directed Acyclic Graph problem using graph traversal techniques like BFS, DFS, an…
逃离火灾
Maximize the time you can stay at your starting position before moving to safely reach the safehouse while avoiding fire…
到达角落需要移除障碍物的最小数目
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…
图中的最长环
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…
感染二叉树需要的总时间
The problem asks to calculate the number of minutes for an infection to spread across all nodes in a binary tree startin…
反转二叉树的奇数层
Reverse the node values at each odd level in a perfect binary tree, preserving the even levels.
移除子树后的二叉树高度
Compute the height of a binary tree efficiently after removing subtrees, using traversal and precomputed node state trac…
树上最大得分和路径
Solve the 'Most Profitable Path in a Tree' problem using graph traversal and depth-first search techniques to maximize A…
逐层排序二叉树所需的最少操作数目
Determine the minimum number of swaps to sort each level of a binary tree using level-wise traversal efficiently.
到达首都的最少油耗
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…
矩阵查询可获得的最大分数
Solve the Maximum Number of Points From Grid Queries problem using two-pointer scanning and invariant tracking.
二进制矩阵中翻转最多一次使路径不连通
Determine if a single cell flip can disconnect a path from the top-left to bottom-right in a binary matrix efficiently u…
在网格图中访问一个格子的最少时间
Compute the fastest path in a grid where each cell has a minimum time requirement using BFS and priority queue technique…
二叉树中的第 K 大层和
Find the kth largest level sum in a binary tree using level-order traversal and sorting.
检查骑士巡视方案
Validate a knight's movement configuration on an n x n chessboard to check if it forms a valid Knight's Tour.
图中的最短环
Find the shortest cycle in a bi-directional graph using BFS for optimal traversal.
最少翻转操作数
Find the minimum number of operations to move a 1 in an array from a given start position to other positions, considerin…
网格图中最少访问的格子数
Determine the minimum number of cells to visit in a grid using state transition dynamic programming and efficient traver…
二叉树的堂兄弟节点 II
Replace each node in a binary tree with the sum of all its cousins by carefully tracking depth and parent relationships.
网格图中鱼的最大数目
Maximize the number of fish that can be caught by performing DFS on an optimal starting point in a grid.
统计完全连通分量的数量
Determine the number of complete connected components in an undirected graph using efficient traversal techniques and gr…
找出最安全路径
Find the Safest Path in a Grid uses binary search and BFS to maximize path safeness from thieves in a grid.
将石头分散到网格图的最少移动次数
Solve the problem of distributing 9 stones across a 3x3 grid with minimal moves using state transition dynamic programmi…
可以到达每一个节点的最少边反转次数
This problem requires solving a graph traversal with edge reversals to ensure every node is reachable in a tree-like str…
使 X 和 Y 相等的最少操作次数
Determine the minimum operations to make two integers equal using increment, decrement, and division efficiently with DP…
按距离统计房屋对数目 I
Determine the number of house pairs at each street distance using graph traversal and breadth-first search efficiently.
最短路径中的边
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…
判断矩形的两个角落是否可达
Determine if there is a valid path from the bottom-left to top-right of a rectangle while avoiding circles.
新增道路查询后的最短距离 I
Solve shortest paths dynamically in a growing graph using BFS, updating distances efficiently after each road addition q…
吃掉所有兵需要的最多移动次数
Calculate the maximum number of moves to eliminate all pawns using BFS, bitmasking, and precise array position math effi…
穿越网格图的安全路径
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…
连接两棵树后最大目标节点数目 I
Maximize the number of target nodes after connecting two trees using binary tree traversal and state tracking.
连接两棵树后最大目标节点数目 II
Maximize the number of target nodes after connecting two trees by analyzing their structure and target relationships.
两天自由外汇交易后的最大货币数
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.
属性图
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.
网格传送门旅游
Find the minimum moves to traverse a 2D grid using standard steps and one-time portal teleports efficiently.
清理教室的最少移动
Solve the "Minimum Moves to Clean the Classroom" problem using array scanning and hash lookup for an optimized solution.
电网维护
Determine which power stations remain connected after maintenance using array scanning and hash lookups to track compone…
总价值可以被 K 整除的岛屿数目
Count the number of islands in a grid where the sum of each island's values is divisible by a given integer k.