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.
3Sum Smaller (较小的三数之和)
Given an array of integers nums and an integer target, return the number of index triplets i < j < k such that nums[i] + num...
Trapping Rain Water (接雨水)
Given n non-negative integers representing an elevation map where each bar has width 1, compute how much water it can trap after r...
Contains Duplicate II (存在重复元素 II)
Given an integer array nums and an integer k, return true if there are two distinct indices i < j such that nums[i] == nums[j] ...
Best Time to Buy and Sell Stock (买卖股票的最佳时机)
You are given an array prices where prices[i] is the price of a stock on day i. You want to maximise profit by choosing a single d...
Minimum Recolors to Get K Consecutive Black Blocks (得到 K 个黑块的最少涂色次数)
You are given a string blocks of 'W' and 'B' and an integer k. You want k consecutive black blocks; one operation recolours a whit...
Minimum Difference Between Highest and Lowest of K Scores (学生分数的最小差值)
You are given a 0-indexed integer array scores and an integer k. Choose k scores so that the difference between the highest and lo...
Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold (大小为 K 且平均值大于等于阈值的子数组数目)
Given an array of integers arr and two integers k and threshold, return the number of sub-arrays of size k whose average is greate...
Grumpy Bookstore Owner (爱生气的书店老板)
A bookstore owner has customers[i] customers at minute i and a grumpy[i] flag that is 1 when they are grumpy (in which case those ...
Max Consecutive Ones II (最大连续 1 的个数 II)
Given a binary array nums, return the maximum number of consecutive 1s obtainable if you can flip at most one 0. Constraints: 1 &l...
Longest Substring with At Most Two Distinct Characters (至多包含两个不同字符的最长子串)
Given a string s, find the length of the longest substring that contains at most two distinct characters. Constraints: 1 <= s.l...
Longest Substring with At Most K Distinct Characters (至多包含 K 个不同字符的最长子串)
Given a string s and an integer k, return the length of the longest substring that contains at most k distinct characters. Constra...
Find K-Length Substrings With No Repeated Characters (长度为 K 的无重复字符子串)
Given a string s and an integer k, return the number of substrings of length k with no repeated characters. Constraints: 1 <= s...
Alternating Groups II (交替组 II)
There is a circle of colors[i] (0 or 1) and an integer k. An alternating group of size k is k consecutive tiles on the circle whos...
Longest Substring Without Repeating Characters (无重复字符的最长子串)
Given a string s, find the length of the longest substring without repeating characters. Constraints: 0 <= s.length <= 5 * 1...
Longest Repeating Character Replacement (替换后的最长重复字符)
You are given a string s and an integer k. You may replace at most k characters with any uppercase letter. Return the length of th...
Permutation in String (字符串的排列)
Given two strings s1 and s2, return true if s2 contains a permutation of s1 as a substring. Constraints: 1 <= s1.length, s2.len...
Frequency of the Most Frequent Element (最高频元素的频数)
The frequency of an element is the number of times it occurs. You can perform at most k operations, each incrementing one element ...
Fruit Into Baskets (水果成篮)
You are given an array fruits where fruits[i] is the type of fruit on tree i. You have two baskets, each of which can hold only on...
Maximum Number of Vowels in a Substring of Given Length (定长子串中元音的最大数目)
Given a string s and an integer k, return the maximum number of vowel letters in any substring of s with length exactly k. Constra...
Minimum Number of Flips to Make the Binary String Alternating (使二进制字符串字符交替的最少反转次数)
You are given a binary string s. In one step you may either remove the first character and append it to the end, or flip any chara...
Defuse the Bomb (拆炸弹)
You have a bomb with a circular code array nums and a key k. If k > 0, replace each element with the sum of the next k elements...
Minimum Size Subarray Sum (长度最小的子数组)
Given an array of positive integers nums and a positive integer target, return the minimal length of a contiguous subarray whose s...
Find K Closest Elements (找到 K 个最接近的元素)
Given a sorted integer array arr, an integer k and an integer x, return the k closest integers to x in ascending order. Ties are b...
Minimum Operations to Reduce X to Zero (将 x 减到 0 的最小操作数)
You are given an array nums and an integer x. In one operation you may remove either the leftmost or the rightmost element and sub...