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.
Custom Sort String (自定义字符串排序)
You are given two strings order and s. Reorder s so that its characters follow order's ordering; characters not in order are place...
Top K Frequent Elements (前 K 个高频元素)
Given an integer array nums and an integer k, return the k most frequent elements in any order. Constraints: 1 <= nums.length &...
Encode and Decode Strings (字符串的编码与解码)
Design an algorithm to encode a list of strings into a single string, and decode that string back into the original list. The inpu...
Range Sum Query 2D - Immutable (二维区域和检索 - 矩阵不可变)
Design a data structure that answers rectangle-sum queries on an immutable 2D matrix. Implement NumMatrix(matrix) and sumRegion(ro...
Analyze User Website Visit Pattern (用户网站访问行为分析)
Given arrays username, timestamp and website describing visits, find the pattern (an ordered triple of websites) visited by the mo...
Product of Array Except Self (除自身以外数组的乘积)
Given an integer array nums, return an array answer where answer[i] is the product of all elements of nums except nums[i]. Constra...
Minimum Number of Operations to Move All Balls to Each Box (移动所有球到每个盒子所需的最小操作数)
You have n boxes given as a binary string boxes, where boxes[i] == '1' means box i contains a ball. In one operation you may move ...
Valid Sudoku (有效的数独)
Determine whether a partially filled 9x9 Sudoku board is valid. Only the filled cells need to be validated, against three rules: e...
Longest Consecutive Sequence (最长连续序列)
Given an unsorted array of integers nums, return the length of the longest run of consecutive integers. The elements need not be a...
Encode and Decode TinyURL (TinyURL 的加密与解密)
Design a class that encodes a long URL into a short URL and decodes it back. There is no restriction on how the encoding works, as...
Brick Wall (砖墙)
There is a rectangular brick wall made of rows of bricks of varying widths but the same height. Draw a vertical line from the top ...
Best Time to Buy and Sell Stock II (买卖股票的最佳时机 II)
You are given an array prices where prices[i] is the price of a stock on day i. You may complete as many transactions as you like ...
Majority Element II (多数元素 II)
Given an integer array nums of size n, find all elements that appear more than n / 3 times. Constraints: 1 <= n <= 5 * 10^4,...
Minimum Index of a Valid Split (合法分割的最小下标)
An element is dominant if it appears more than half the time in an array. Given nums with a dominant element, find the minimum ind...
Subarray Sum Equals K (和为 K 的子数组)
Given an array of integers nums and an integer k, return the total number of contiguous subarrays whose sum equals k. Constraints:...
Subarray Sums Divisible by K (和可被 K 整除的子数组)
Given an integer array nums and an integer k, return the number of non-empty subarrays whose sum is divisible by k. Constraints: 1...
Make Sum Divisible by P (使数组和能被 P 整除)
Given an array of positive integers nums and an integer p, remove the shortest subarray (possibly empty) so that the sum of the re...
Unique Length-3 Palindromic Subsequences (长度为 3 的不同回文子序列)
Given a string s, return the number of unique palindromic subsequences of length 3. A subsequence is formed by deleting characters...
Number of Sub-arrays With Odd Sum (和为奇数的子数组数目)
Given an array of integers arr, return the number of subarrays with an odd sum. The answer may be large, so return it modulo 10^9 ...
Minimum Number of Swaps to Make the String Balanced (使字符串平衡的最少交换次数)
Given a 0-indexed string s of even length consisting of [ and ], return the minimum number of swaps (of any two indices) needed to...
Number of Pairs of Interchangeable Rectangles (可互换矩形的组数)
You are given n rectangles, each [width_i, height_i]. Two rectangles are interchangeable if their width-to-height ratios are equal...
Maximum Product of the Length of Two Palindromic Subsequences (两个回文子序列长度的最大乘积)
Given a string s, find two disjoint palindromic subsequences of s and return the maximum product of their lengths. If no two disjo...
Grid Game (网格游戏)
Two robots play on a 2 x n grid. Robot 1 starts at (0, 0) and moves only right; it may drop to row 1 at any column, after which it...
Find All Anagrams in a String (找到字符串中所有字母异位词)
Given two strings s and p, return all start indices of p's anagrams in s. Constraints: 1 <= s.length, p.length <= 3 * 10^4, ...