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.
Remove All Adjacent Duplicates in String II (删除字符串中的所有相邻重复项 II)
Given a string s and an integer k, repeatedly delete k adjacent equal characters until no more deletions are possible, and return ...
Reverse Substrings Between Each Pair of Parentheses (反转每对括号间的子串)
You are given a string s consisting of lowercase letters and parentheses. Reverse the substrings inside each pair of matching pare...
Ternary Expression Parser (三元表达式解析器)
Given a string expression representing a ternary expression, evaluate it and return the result. The expression is always valid and...
Find Permutation (寻找排列)
A permutation perm of 1..n can be derived from a string s of length n - 1: s[i] == 'I' means perm[i] < perm[i+1] and s[i] == 'D...
Basic Calculator III (基本计算器 III)
Implement a basic calculator to evaluate a simple expression string containing non-negative integers, +, -, *, /, ( and ). Divisio...
Max Stack (最大栈)
Design a max stack supporting push(x), pop(), top(), peekMax() and popMax(). popMax() removes and returns the maximum element; if ...
Minimum String Length After Removing Substrings (删除子串后的字符串最小长度)
Given a string s of uppercase letters, repeatedly remove any occurrence of "AB" or "CD" until no more exist. Return the minimum po...
Clear Digits (清除数字)
You are given a string s. Repeatedly remove every digit and the closest non-digit character to its left, until no digits remain. R...
Minimum Add to Make Parentheses Valid (使括号有效的最少添加)
A parentheses string is valid if it is empty, or can be written as AB or (A) where A and B are valid. Given a string s, return the...
Maximum Width Ramp (最大宽度坡)
A ramp is a pair (i, j) with i < j and nums[i] <= nums[j]. The width is j - i. Given an array nums, return the maximum width...
Basic Calculator II (基本计算器 II)
Given a string s representing an expression with non-negative integers and the operators +, -, *, /, evaluate it. Division truncat...
132 Pattern (132 模式)
Given an array of n integers nums, return true if there is a 132 pattern: indices i < j < k with nums[i] < nums[k] < n...
Flatten Nested List Iterator (扁平化嵌套列表迭代器)
This is an interactive problem. You are given a nested list of integers, where each element is either an integer or a list. Implem...
Sum of Subarray Minimums (子数组的最小值之和)
Given an array of integers arr, return the sum of min(b) over every contiguous subarray b, modulo 10^9 + 7. Constraints: 1 <= a...
Maximum Frequency Stack (最大频率栈)
Design a stack-like structure that pops the most frequent element. If there is a tie, the element closest to the top of the stack ...
Robot Collisions (机器人碰撞)
You are given arrays positions, healths and directions describing robots. Robots move in their direction at the same speed; when t...
Number of Visible People in a Queue (队列中可以看到的人数)
There are n people in a queue, heights[i] is the height of the i-th person. A person can see the next person to the right who is t...
Largest Rectangle in Histogram (柱状图中最大的矩形)
Given an array heights representing the heights of bars of width 1 in a histogram, return the area of the largest rectangle that f...
Shortest Subarray with Sum at Least K (和至少为 K 的最短子数组)
Given an integer array nums and an integer k, return the length of the shortest non-empty subarray with a sum of at least k. If no...
Parsing A Boolean Expression (解析布尔表达式)
A boolean expression is a string containing t (true), f (false), !(expr), &(expr,...) or |(expr,...). Evaluate it and return t...
Number of Atoms (原子的数量)
Given a chemical formula, return the count of each atom as a string in the form Name followed by its count (omitted when the count...
Binary Tree Inorder Traversal (二叉树的中序遍历)
Given the root of a binary tree, return its in-order traversal (left, root, right) as a list of values. Constraints: the number of...
Binary Tree Preorder Traversal (二叉树的前序遍历)
Given the root of a binary tree, return its pre-order traversal (root, left, right) as a list of values. Constraints: the number o...
Binary Tree Postorder Traversal (二叉树的后序遍历)
Given the root of a binary tree, return its post-order traversal (left, right, root) as a list of values. Constraints: the number ...