NeetCode Comprehensive Algorithm Bank & Offline Handbook
Synchronized bilingual toggle with dual NeetCode & LeetCode problem numbering and direct links. Features step-by-step logic, benchmark Python3 code, complexity analysis, interview pitfalls, and standalone offline exports.
Graph Valid Tree (以图判树)
You are given n nodes labelled 0..n-1 and a list of undirected edges. Return whether the edges form a valid tree. Constraints: 1 &...
Course Schedule IV (课程表 IV)
There are numCourses courses. Given prerequisites and queries where queries[i] = [a, b], return a boolean array where the i-th ent...
Check if Move is Legal (检查操作是否合法)
You are given an 8x8 board with 'W', 'B' and '.', and a move at (rMove, cMove) with color. The move is legal if it forms a bracket...
Shortest Bridge (最短的桥)
You are given an n x n binary grid with exactly two islands. Return the shortest bridge length: the minimum number of 0s that must...
Shortest Path in Binary Matrix (二进制矩阵中的最短路径)
Given an n x n binary matrix grid, return the length of the shortest clear path from the top-left to the bottom-right, where all c...
Number of Connected Components in an Undirected Graph (无向图中连通分量的数目)
You are given n nodes labelled 0..n-1 and a list of undirected edges. Return the number of connected components. Constraints: 1 &l...
Redundant Connection (冗余连接)
In a graph that started as a tree with n nodes and one extra edge was added, given the edges list, return the extra edge. If there...
Accounts Merge (账户合并)
Given a list of accounts where accounts[i] = [name, email1, email2, ...], merge accounts that share any email. Two accounts belong...
Find Closest Node to Given Two Nodes (找到离给定两个节点最近的节点)
You are given a directed graph where edges[i] is the single outgoing edge from node i (-1 means none), and two starting nodes node...
As Far from Land as Possible (地图分析)
Given an n x n grid containing only 0 (water) and 1 (land), return the maximum Manhattan distance from a water cell to its nearest...
Shortest Path with Alternating Colors (颜色交替的最短路径)
You are given a directed graph with red edges and blue edges. Return the shortest path length from node 0 to each node such that t...
Minimum Fuel Cost to Report to the Capital (到达首都的最少油耗)
There is a tree of n cities with city 0 as the capital. roads[i] = [a, b] is an undirected road. Each city has one representative,...
Minimum Score of a Path Between Two Cities (两个城市间路径的最小分数)
You are given n cities and roads[i] = [a, b, distance]. A path's score is its minimum road distance. Return the minimum possible s...
Number of Closed Islands (统计封闭岛屿的数目)
Given an m x n binary matrix grid, return the number of closed islands: maximal 4-directionally connected groups of 0s completely ...
Number of Enclaves (飞地的数量)
Given an m x n binary matrix grid where 0 is sea and 1 is land, return the number of land cells from which you cannot walk off the...
Number of Provinces (省份数量)
There are n cities, some connected. Given an n x n adjacency matrix isConnected, return the number of provinces (connected compone...
Regions Cut By Slashes (由斜杠划分区域)
An n x n grid of /, \ and represents a picture divided into regions by the slashes. Return the number of regions. Constraints: 1...
Minimum Number of Vertices to Reach All Nodes (可以到达所有点的最少点数目)
Given a DAG with n vertices and edges, return the smallest set of vertices from which all other vertices are reachable. Constraint...
Is Graph Bipartite? (判断二分图)
There is an undirected graph with n nodes where graph[i] lists the neighbours of node i. Return whether the graph is bipartite: th...
Count the Number of Complete Components (统计完全连通分量的数量)
You are given an undirected graph with n vertices and edges. A connected component is complete if every pair of its vertices has a...
Evaluate Division (除法求值)
You are given equations where equations[i] = [Ai, Bi] and values[i] means Ai / Bi = values[i]. Given queries, return the answer to...
Detonate the Maximum Bombs (引爆最多的炸弹)
Given an m x n grid of characters, return whether there is a cycle of length 4 or more: four or more cells of the same value conne...
Find All Possible Recipes from Given Supplies (从给定原材料中找到所有可以做出的菜)
You are given recipes, ingredients (parallel arrays) and supplies (initially available items). A recipe can be made when all its i...
Shortest Distance After Road Addition Queries I (新增道路查询后的最短距离 I)
There are n cities numbered 0..n-1 with a directed road from i to i+1 for each i. For each query [u, v], add a road u -> v and ...