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.
Strobogrammatic Number (中心对称数)
A strobogrammatic number is one that looks the same when rotated 180 degrees. The valid digit pairs are 0-0, 1-1, 6-9 and 8-8. Giv...
Two Sum Less Than K (小于 K 的两数之和)
Given an array nums and an integer k, return the maximum nums[i] + nums[j] where i < j and the sum is less than k. If no such p...
Adding Spaces to a String (向字符串添加空格)
You are given a 0-indexed string s and a 0-indexed integer array spaces listing the indices at which spaces should be inserted. Re...
String Compression (压缩字符串)
Given an array of characters chars, compress it in place using run-length encoding: for each group of consecutive identical charac...
Remove Duplicates from Sorted Array II (删除有序数组中的重复项 II)
Given an integer array nums sorted in non-decreasing order, remove duplicates in place so that each unique element appears at most...
Partition Array According to Given Pivot (根据给定数字划分数组)
Given an integer array nums and an integer pivot, rearrange nums so that elements less than pivot come first, then elements equal ...
Two Sum II - Input Array Is Sorted (两数之和 II - 输入有序数组)
Given a 1-indexed array of integers numbers sorted in non-decreasing order, find two numbers that add up to a target and return th...
3Sum (三数之和)
Given an integer array nums, return all triplets [nums[i], nums[j], nums[k]] with i < j < k such that the three sum to zero....
4Sum (四数之和)
Given an array nums and a target, return all unique quadruplets [a, b, c, d] that sum to target. Constraints: 1 <= nums.length ...
Rotate Array (轮转数组)
Given an integer array nums, rotate it to the right by k steps, in place. Constraints: 1 <= nums.length <= 10^5, 0 <= k &...
Container With Most Water (盛最多水的容器)
You are given an array height of n non-negative integers representing vertical lines. Find two lines that, together with the x-axi...
Number of Subsequences That Satisfy the Given Sum Condition (满足条件的子序列数目)
Given an array nums and an integer target, count the number of non-empty subsequences whose minimum plus maximum is at most target...
Array With Elements Not Equal to Average of Neighbors (构造元素不等于两相邻元素平均值的数组)
Given an array nums, rearrange it so that no element equals the average of its neighbours. Return any valid arrangement. Constrain...
Divide Players Into Teams of Equal Skill (划分技能点相等的团队)
You are given an array skill of even length where skill[i] is the skill of player i. Divide the players into teams of 2 such that ...
Boats to Save People (救生艇)
You are given an array people where people[i] is the weight of the i-th person, and a limit on the total weight each boat can carr...
K-th Symbol in Grammar (第 K 个语法符号)
We build row 1 as 0. Row i is obtained from row i-1 by replacing each 0 with 01 and each 1 with 10. Given n and k (1-indexed), ret...
Minimum Time to Make Rope Colorful (使绳子变成彩色的最短时间)
You are given a string colors and an array neededTime where neededTime[i] is the time to remove the i-th balloon. Two adjacent bal...
Rearrange Array Elements by Sign (按符号重排数组)
Given an integer array nums with an equal number of positive and negative integers, rearrange it so that positives occupy the even...
Bag of Tokens (令牌放置)
You start with power tokens and score = 0. You may play a token face up if you have at least tokens[i] power (gaining 1 score and ...
Minimum Length of String After Deleting Similar Ends (删除字符串两端相同字符后的最短长度)
Given a string s consisting only of characters a, b and c, repeatedly delete a prefix and a suffix that both consist of the same c...
Sentence Similarity III (句子相似性 III)
A sentence is similar to another if you can insert an arbitrary sentence (possibly empty) inside one of them to make them equal. G...
Meeting Scheduler (安排会议日程)
Given the availability time slots of two people as slots1 and slots2, and a meeting duration, return the earliest time slot that w...
Product of Two Run-Length Encoded Arrays (两个行程编码数组的积)
Two run-length encoded arrays encoded1 and encoded2 represent arrays of the same length, each entry [value, frequency]. Return the...
Sort Transformed Array (有序转化数组)
Given a sorted array nums and integers a, b, c, apply the quadratic function f(x) = a*x^2 + b*x + c to every element and return th...