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.
Binary Search Tree Iterator (二叉搜索树迭代器)
Implement a BSTIterator over the in-order traversal of a binary search tree, supporting next() (the next smallest value) and hasNe...
Validate Binary Tree Nodes (验证二叉树)
You have n binary tree nodes numbered 0..n-1, given leftChild and rightChild arrays where -1 means no child. Return true if they f...
Find Largest Value in Each Tree Row (在每个树行中找最大值)
Given the root of a binary tree, return an array of the largest value in each level. Constraints: the number of nodes is in [0, 10...
Pseudo-Palindromic Paths in a Binary Tree (二叉树中的伪回文路径)
Given the root of a binary tree where node values are digits 1..9, a path is pseudo-palindromic if at most one digit appears an od...
Even Odd Tree (奇偶树)
A binary tree is even-odd if: every even-indexed level (the root is level 0) has strictly increasing values that are all odd, and ...
Smallest String Starting From Leaf (从叶结点开始的最小字符串)
Given the root of a binary tree where each node holds a value from 0 to 25 (mapping to a-z), each root-to-leaf path forms a string...
Delete Leaves With a Given Value (删除给定值的叶子节点)
Given the root of a binary tree and an integer target, repeatedly delete all leaf nodes with value target until no more such leave...
Delete Nodes And Return Forest (删点成林)
Given the root of a binary tree and an array to_delete of values to remove, delete those nodes and return the roots of the resulti...
Distribute Coins in Binary Tree (在二叉树中分配硬币)
Given the root of a binary tree with n nodes, each node has node.val coins, and there are n coins in total. In one move you may mo...
Convert BST to Greater Tree (把二叉搜索树转换为累加树)
Given the root of a binary search tree, convert it to a greater sum tree: every node's new value is the sum of all values greater ...
Step-By-Step Directions From a Binary Tree Node to Another (从二叉树一个节点到另一个节点每一步的方向)
Given the root of a binary tree with unique values from 1 to n, and two values startValue and endValue, return the shortest path f...
Inorder Successor in BST II (二叉搜索树中的中序后继 II)
Given a node in a binary search tree where every node has a parent pointer, return its in-order successor (the next node in the in...
Tree Diameter (树的直径)
Given an undirected tree represented as a list of edges, return its diameter: the number of edges on the longest path between any ...
Convert Binary Search Tree to Sorted Doubly Linked List (将二叉搜索树转化为排序的双向链表)
Convert a binary search tree into a sorted circular doubly linked list in place, where left is the predecessor and right is the su...
Binary Tree Upside Down (上下翻转二叉树)
Given the root of a binary tree, turn it upside down: the original leftmost path becomes the new left spine, with each original le...
Recover a Tree From Preorder Traversal (从先序遍历还原二叉树)
We run a pre-order depth-first search on a binary tree, outputting D dashes followed by the node value, where D is the node's dept...
Binary Tree Maximum Path Sum (二叉树中的最大路径和)
A path in a binary tree is a sequence of nodes where each pair of adjacent nodes is connected by an edge; a node may appear at mos...
Serialize and Deserialize Binary Tree (二叉树的序列化与反序列化)
Design an algorithm to serialise a binary tree into a string and deserialise that string back into the original tree. Constraints:...
Count Prefix and Suffix Pairs I (统计前后缀下标对 I)
You are given a 0-indexed array of strings words. Return the number of pairs (i, j) with i < j such that words[i] is both a pre...
Implement Trie (Prefix Tree) (实现 Trie(前缀树))
Implement a trie (prefix tree) with insert(word), search(word) and startsWith(prefix). Constraints: 1 <= word.length, prefix.le...
Design Add and Search Words Data Structure (添加与搜索单词 - 数据结构设计)
Design a data structure supporting addWord(word) and search(word), where search may contain . matching any single letter. Constrai...
Counting Words With a Given Prefix (统计包含给定前缀的字符串)
You are given an array of strings words and a string pref. Return the number of strings in words that contain pref as a prefix. Co...
Remove Sub-Folders from the Filesystem (删除子文件夹)
Given a list of absolute folder paths folder, remove all sub-folders and return the remaining paths in any order. Constraints: 1 &...
Extra Characters in a String (字符串中的额外字符)
You are given a string s and a dictionary of words. Break s into the dictionary words plus leftover single characters; return the ...