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.
Minimum Number of Days to Disconnect Island (使陆地分离的最少天数)
You are given an m x n binary grid where 1 is land. In one day you may change one land cell to water. Return the minimum number of...
Second Minimum Time to Reach Destination (到达目的地的第二短时间)
There are n intersections connected by bidirectional roads, each traversal taking time minutes. Traffic lights change every change...
Find Minimum Diameter After Merging Two Trees (合并两棵树后的最小直径)
You are given two trees described by edges1 and edges2. You must add exactly one edge connecting a node of the first tree to a nod...
Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree (找到最小生成树里的关键边和伪关键边)
You are given a weighted undirected graph with n nodes and edges[i] = [u, v, w]. Return a list of two lists: the indices of the cr...
Bus Routes (公交路线)
You are given routes where routes[i] is the list of stops of bus route i, plus source and target. You start at source and may ride...
Build a Matrix With Conditions (给定条件下构造矩阵)
You are given a positive integer k, rowConditions where rowConditions[i] = [above, below] means the value above must be in a row s...
Greatest Common Divisor Traversal (最大公约数遍历)
You are given a 0-indexed array nums. You may traverse from index i to index j if gcd(nums[i], nums[j]) > 1. Return whether the...
Divide Nodes Into the Maximum Number of Groups (将节点分成尽可能多的组)
You are given an undirected graph of n nodes and edges. Divide the nodes into the maximum number of groups such that: every edge c...
Climbing Stairs (爬楼梯)
You are climbing a staircase with n steps. Each move you may climb either 1 or 2 steps. Return the number of distinct ways to reac...
Min Cost Climbing Stairs (使用最小花费爬楼梯)
You are given an integer array cost where cost[i] is the price of stepping on stair i. Once you pay, you may climb one or two step...
N-th Tribonacci Number (第 N 个泰波那契数)
The Tribonacci sequence is defined by T0 = 0, T1 = 1, T2 = 1, and Tn = Tn-1 + Tn-2 + Tn-3 for n >= 3. Given n, return Tn. Const...
House Robber (打家劫舍)
You are given a non-negative integer array nums where nums[i] is the money in house i. Return the maximum amount you can rob witho...
House Robber II (打家劫舍 II)
The houses are now arranged in a circle, so the first and last houses are adjacent. Given nums, return the maximum amount you can ...
Paint House (粉刷房子)
You are given an n x 3 matrix costs where costs[i][j] is the cost of painting house i with colour j (colours 0, 1, 2). Paint every...
Paint Fence (栅栏涂色)
There are n fence posts and k colours. Paint the posts so that no more than two adjacent posts share the same colour. Return the n...
4 Keys Keyboard (4 键键盘)
Imagine a keyboard with four keys: A (print one letter A), Ctrl-A (select all), Ctrl-C (copy the selection), and Ctrl-V (paste the...
Handshakes That Don't Cross (不相交的握手)
numPeople people stand in a circle and each shakes exactly one other person's hand, with no two handshakes crossing. Return the nu...
Longest Palindromic Substring (最长回文子串)
Given a string s, return the longest palindromic substring in s. A palindrome reads the same forwards and backwards. Constraints: ...
Palindromic Substrings (回文子串)
Given a string s, return the number of palindromic substrings in it. Substrings with different start or end indices are counted se...
Decode Ways (解码方法)
A message of digits can be decoded where A through Z map to the digit strings 1 through 26. Given a digit string s, return the num...
Coin Change (零钱兑换)
You are given an integer array coins of distinct denominations and an integer amount. You have an unlimited supply of each coin. R...
Maximum Product Subarray (乘积最大子数组)
Given an integer array nums, find a contiguous subarray with the largest product and return that product. Constraints: 1 <= num...
Word Break (单词拆分)
Given a string s and a dictionary wordDict, return whether s can be segmented into a space-separated sequence of one or more dicti...
Longest Increasing Subsequence (最长递增子序列)
Given an integer array nums, return the length of the longest strictly increasing subsequence. A subsequence keeps the original or...