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.
Clone N-ary Tree (克隆 N 叉树)
You are given a reference to an N-ary tree. Return a deep copy of the tree. Constraints: the number of nodes is in [0, 10^4], 0 &l...
Find Root of N-Ary Tree (找到 N 叉树的根节点)
You are given all the nodes of an N-ary tree as an array. Each node has a unique value and a children list. Return the root of the...
Diameter of N-Ary Tree (N 叉树的直径)
Given the root of an N-ary tree, return its diameter: the length of the longest path between any two nodes, measured in edges. Con...
Nested List Weight Sum II (嵌套列表加权和 II)
This is an interactive problem. You are given a nested list of integers where each element is an integer or a list. Return the sum...
Closest Binary Search Tree Value II (最接近的二叉搜索树值 II)
Given the root of a binary search tree, a target and an integer k, return the k values in the BST closest to the target, in any or...
Serialize and Deserialize N-ary Tree (序列化和反序列化 N 叉树)
Design an algorithm to serialise and deserialise an N-ary tree. Constraints: the number of nodes is in [0, 10^4], 0 <= Node.val...
Encode N-ary Tree to Binary Tree (将 N 叉树编码为二叉树)
Design an algorithm to convert an N-ary tree into a binary tree and back. The binary tree must follow the left-child, right-siblin...
Create Binary Tree From Descriptions (根据描述创建二叉树)
You are given a 2D array descriptions where descriptions[i] = [parent, child, isLeft] describes a binary tree edge. Return the roo...
Populating Next Right Pointers in Each Node (填充每个节点的下一个右侧节点指针)
You are given a perfect binary tree where all leaves are at the same depth and every parent has two children. Each node has an ext...
Construct String from Binary Tree (根据二叉树创建字符串)
Given the root of a binary tree, construct a string of parentheses and integers from a pre-order traversal: an empty tree is "", a...
Lowest Common Ancestor of a Binary Tree (二叉树的最近公共祖先)
Given a binary tree and two nodes p and q, return their lowest common ancestor: the deepest node that has both as descendants (a n...
Lowest Common Ancestor of a Binary Tree III (二叉树的最近公共祖先 III)
Given two nodes p and q in a binary tree where each node has a parent pointer, return their lowest common ancestor. Constraints: t...
Lowest Common Ancestor of a Binary Search Tree (二叉搜索树的最近公共祖先)
Given a binary search tree and two nodes p and q, return their lowest common ancestor (LCA). Constraints: the number of nodes is i...
Insert into a Binary Search Tree (二叉搜索树中的插入操作)
You are given the root of a binary search tree and a value val to insert. Insert the value and return the root. The input tree is ...
Delete Node in a BST (删除二叉搜索树中的节点)
Given the root of a binary search tree and a key, delete the node with that key and return the root. The tree must remain a valid ...
Binary Tree Level Order Traversal (二叉树的层序遍历)
Given the root of a binary tree, return its level-order traversal: a list of lists, where each inner list holds the values at one ...
Binary Tree Right Side View (二叉树的右视图)
Given the root of a binary tree, imagine standing on the right side of it and return the values of the nodes visible from top to b...
Reverse Odd Levels of Binary Tree (反转二叉树的奇数层)
Given the root of a perfect binary tree, reverse the node values at each odd level (the root is level 0). Return the root. Constra...
Minimum Number of Operations to Sort a Binary Tree by Level (逐层排序二叉树所需的最少操作数目)
You are given the root of a binary tree. In one operation you may swap the values of two nodes on the same level. Return the minim...
Kth Largest Sum in a Binary Tree (二叉树中的第 K 大层和)
You are given the root of a binary tree and a positive integer k. Return the k-th largest level sum (the sum of node values at eac...
Cousins in Binary Tree II (二叉树的堂兄弟节点 II)
Given the root of a binary tree, replace each node's value with the sum of all values on the same level that are not its cousins' ...
Minimum Distance Between BST Nodes (二叉搜索树节点最小距离)
Given the root of a binary search tree, return the minimum difference between the values of any two distinct nodes. Constraints: t...
Symmetric Tree (对称二叉树)
Given the root of a binary tree, check whether it is mirror-symmetric around its centre. Constraints: the number of nodes is in [1...
Linked List in Binary Tree (二叉树中的链表)
Given a binary tree root and a linked list head, return true if the list's values form a downward path in the tree. Constraints: t...