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.
Merge Triplets to Form Target Triplet (合并若干三元组以形成目标三元组)
You are given a 2D array triplets and an integer array target. In one operation pick two triplets and replace them with their elem...
Partition Labels (划分字母区间)
You are given a string s. Partition it into as many parts as possible so that each letter appears in at most one part, and return ...
Valid Parenthesis String (有效的括号字符串)
Given a string s containing only (, ) and *, where * may be treated as (, ), or the empty string, return true if s can be a valid ...
Check if a Parentheses String Can Be Valid (判断一个括号字符串是否有效)
You are given a string s of ( and ), and a binary string locked where 1 means the character is locked (unchangeable) and 0 means i...
Eliminate Maximum Number of Monsters (消灭怪物的最大数量)
You are given dist[i] (distance from the city) and speed[i] (speed per minute) for n monsters. Each minute you may eliminate one m...
Two City Scheduling (两地调度)
A company must send 2n people to two cities, n to each. costs[i] = [costA, costB] is the cost of sending person i to city A or cit...
Maximum Length of Pair Chain (最长数对链)
You are given n pairs where pairs[i] = [left, right] and left < right. A pair [c, d] can follow [a, b] in a chain if b < c. ...
Best Sightseeing Pair (最佳观光组合)
Given an array values, the score of a pair (i, j) with i < j is values[i] + values[j] + i - j. Return the maximum score. Constr...
Make Lexicographically Smallest Array by Swapping Elements (交换得到字典序最小的数组)
Given an array nums and an integer limit, you may swap nums[i] and nums[j] any number of times if |nums[i] - nums[j]| <= limit....
Minimum Deletions to Make Character Frequencies Unique (字符频次唯一的最小删除次数)
A string s is good if no two different characters have the same frequency. Return the minimum number of deletions to make s good. ...
Minimum Deletions to Make String Balanced (使字符串平衡的最少删除次数)
You are given a string s of a and b. A string is balanced if no a appears after a b. In one deletion you may remove any character....
Candy (分发糖果)
There are n children in a line, each with a ratings[i]. Give each child at least one candy; any child with a higher rating than an...
Remove Colored Pieces if Both Neighbors are the Same Color (如果相邻两个颜色均相同则删除当前颜色)
There is a row of pieces coloured A or B. Alice and Bob take turns (Alice first); a player removes one of their own pieces that ha...
Maximum Score From Removing Substrings (删除子字符串的最大得分)
You are given a string s and two integers x and y. You may remove the substring ab for x points or ba for y points, any number of ...
Maximum Element After Decreasing and Rearranging (减小和重新排列数组后的最大元素)
You are given an array of positive integers arr. You may rearrange the elements and decrease any element (but never increase one)....
Number of Laser Beams in a Bank (银行中的激光束数量)
A bank is represented as an m x n grid of strings where bank[i] describes row i: 1 is a security device and 0 is empty. A laser be...
Reveal Cards In Increasing Order (按递增顺序显示卡牌)
You have a deck of distinct integers. The reveal process is: take the top card, reveal it, then (if cards remain) move the new top...
Construct String With Repeat Limit (构造限制重复的字符串)
Given a string s and an integer repeatLimit, construct the lexicographically largest string from the characters of s such that no ...
Find Valid Matrix Given Row and Column Sums (给定行和列的和求可行矩阵)
You are given two arrays rowSum (length m) and colSum (length n). Construct an m x n matrix of non-negative integers whose row sum...
Score After Flipping Matrix (翻转矩阵后的得分)
You are given an m x n binary matrix grid. A move picks any row or column and flips every value in it. The score of the matrix is ...
Flip Columns For Maximum Number of Equal Rows (按列翻转得到最大值等行数)
You are given an m x n binary matrix. Choose any set of columns and flip every value in those columns. Return the maximum number o...
Maximum Matrix Sum (最大方阵和)
You are given an m x n integer matrix. An operation chooses two adjacent cells (sharing a side) and multiplies both by -1. You may...
Make Two Arrays Equal by Reversing Subarrays (通过翻转子数组使两个数组相等)
You are given two integer arrays target and arr of the same length. In one operation you may reverse any contiguous subarray of ar...
Shortest Subarray to be Removed to Make Array Sorted (删除最短的子数组使剩余数组有序)
Given an integer array arr, you may remove one contiguous subarray so that the remaining elements are non-decreasing. Return the m...