识别信号
- Do you understand how BFS guarantees the shortest path in a word transformation sequence?
- Can you explain why a hash table improves the performance of this problem?
- Do you understand how Depth-First Search can be applied to matrix traversal?
解题流程
- 1. 明确窗口/状态定义
- 2. 更新状态并维护约束
- 3. 用边界样例验证
常见失分点
- Not checking if `endWord` is in the `wordList` before starting the BFS, leading to unnecessary computation.
- Failing to properly mark border 'O's as safe, leading to incorrect regions being transformed.
- Failing to mark visited cells, causing infinite loops or double-counting.
推荐题单梯度
单词接龙
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.
岛屿数量
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…
添加与搜索单词 - 数据结构设计
Build a WordDictionary supporting dynamic word addition and search with wildcard matching efficiently using Trie and DFS…
最小高度树
Identify all roots of a tree that produce minimum height using graph indegree analysis and topological trimming.
水壶问题
Determine if two jugs with given capacities can measure an exact target amount using math and DFS strategies efficiently…
字典序排数
Generate all numbers from 1 to n in lexicographical order using a depth-first search pattern optimized with trie logic f…
接雨水 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.
棋盘上的战舰
Count the number of non-overlapping battleships on a 2D board using array traversal and depth-first search patterns effi…
最小基因变化
Determine the minimum number of single-character gene mutations to reach the target gene using BFS and a hash table look…
岛屿的周长
Determine the perimeter of an island in a grid of land and water cells using DFS or BFS.
扫雷游戏
Solve the Minesweeper game by updating revealed squares and handling clicks with Depth-First Search and Array manipulati…
数组嵌套
Find the longest nested set in a permutation array using a depth-first traversal, handling cycles efficiently for medium…
为高尔夫比赛砍树
Determine the minimum steps to cut all trees in a forest matrix in ascending height order using BFS traversal and priori…
实现一个魔法字典
Design a Magic Dictionary to allow searching with one-character modifications, using Hash Table and String techniques.
岛屿的最大面积
Find the largest connected land area in a binary grid using array traversal and depth-first search efficiently.
图像渲染
Flood Fill is an array and DFS problem where you change connected pixels to a target color efficiently using recursion o…
隔离病毒
Contain Virus involves using array-based Depth-First Search to contain viral spread by building walls around infected re…
金字塔转换矩阵
The Pyramid Transition Matrix problem requires determining whether a pyramid can be formed with given blocks and valid p…
找到最终的安全状态
Solve the problem of finding eventual safe states in a directed graph using depth-first search and topological sorting.
最大人工岛
Calculate the largest island size by converting at most one zero in a binary grid using array and DFS techniques efficie…
喧闹和富有
Determine the quietest person richer than each individual using graph indegree analysis and topological ordering techniq…
相似度为 K 的字符串
K-Similar Strings involves finding the minimal number of swaps to transform one string into another through character sw…
获取所有钥匙的最短路径
Find the minimum steps to collect all keys in a grid using BFS and bitmasking, handling locks efficiently.
蛇梯棋
Solve the Snakes and Ladders problem using a BFS strategy to efficiently navigate the board and reach the final square.
最短的桥
Find the minimum flips to connect two separate islands in a binary matrix using Array and DFS techniques efficiently.
腐烂的橘子
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 …
二进制矩阵中的最短路径
Find the shortest clear path in a binary matrix using BFS, carefully handling obstacles and diagonal movements for effic…
颜色交替的最短路径
Solve the shortest path problem with alternating edge colors using graph traversal and BFS.
项目管理
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.
推箱子
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…
网格中的最短路径
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…
跳跃游戏 III
Jump Game III challenges you to determine if you can reach any zero in an array using jumps defined by array values, tes…
使网格图至少有一条有效路径的最小代价
Determine the minimum cost to create at least one valid path from the top-left to bottom-right in a directional grid.
检查网格中是否存在有效路径
Check if there is a valid path from the upper-left to the bottom-right corner of a grid using depth-first search.
课程表 IV
Determine if one course is a prerequisite of another using graph indegree tracking and topological ordering 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.
执行操作后字典序最小的字符串
Optimize a string through rotations and additions to get the lexicographically smallest possible result using string man…
执行交换操作后的最小汉明距离
Solve Minimize Hamming Distance After Swap Operations by grouping swappable indices and matching value counts inside eac…
地图中的最高点
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.
找到所有的农场组
Identify all rectangular farmland groups in a binary matrix using array traversal and depth-first search efficiently.
网络空闲的时刻
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…
参加会议的最多员工数
Determine the maximum employees to invite based on favorite adjacency constraints using graph indegree and topological o…
价格范围内最高排名的 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…
相邻字符不同的最长路径
Find the longest path in a tree where adjacent nodes have different characters using graph DFS and topological reasoning…
到达角落需要移除障碍物的最小数目
Find the minimum obstacles to remove in a 2D grid to reach the bottom-right corner using BFS graph traversal techniques.
图中的最长环
The problem asks to find the longest cycle in a directed graph with specific edge constraints.
在网格图中访问一个格子的最少时间
Compute the fastest path in a grid where each cell has a minimum time requirement using BFS and priority queue technique…
检查骑士巡视方案
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…
网格图中鱼的最大数目
Maximize the number of fish that can be caught by performing DFS on an optimal starting point in a grid.
按距离统计房屋对数目 I
Determine the number of house pairs at each street distance using graph traversal and breadth-first search efficiently.
新增道路查询后的最短距离 I
Solve shortest paths dynamically in a growing graph using BFS, updating distances efficiently after each road addition q…
穿越网格图的安全路径
Determine if you can safely traverse a binary grid from top-left to bottom-right using limited health points.
总价值可以被 K 整除的岛屿数目
Count the number of islands in a grid where the sum of each island's values is divisible by a given integer k.