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.
Get Equal Substrings Within Budget (尽可能使字符串相等)
You are given two strings s and t of the same length, and an integer maxCost. Changing s[i] to t[i] costs |s[i] - t[i]|. Return th...
Number of Substrings Containing All Three Characters (包含所有三种字符的子字符串数目)
Given a string s consisting only of the characters a, b and c, return the number of substrings containing at least one occurrence ...
Binary Subarrays With Sum (和相同的二元子数组)
Given a binary array nums and an integer goal, return the number of non-empty subarrays with a sum equal to goal. Constraints: 1 &...
Count Number of Nice Subarrays (统计「优美子数组」数目)
Given an array of integers nums and an integer k, return the number of nice subarrays: contiguous subarrays with exactly k odd num...
Subarray Product Less Than K (乘积小于 K 的子数组)
Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all elements is s...
Max Consecutive Ones III (最大连续 1 的个数 III)
Given a binary array nums and an integer k, return the maximum number of consecutive 1s obtainable if you can flip at most k zeros...
Find the Power of K-Size Subarrays I (长度为 K 的子数组的能量值 I)
You are given an array nums of n integers and an integer k. For each subarray of size k, it is powerful if its elements can be rea...
Maximum Sum of Distinct Subarrays With Length K (长度为 K 子数组中的最大和)
You are given an integer array nums and an integer k. Find the maximum subarray sum for a subarray of length k where all elements ...
Length of Longest Subarray With at Most K Frequency (最多 K 个重复元素的最长子数组)
Given an array of integers nums and an integer k, return the length of the longest subarray where the frequency of each element is...
Count Subarrays Where Max Element Appears at Least K Times (统计最大元素出现至少 K 次的子数组)
You are given an integer array nums and a positive integer k. Return the number of subarrays in which the maximum element of nums ...
Maximum Beauty of an Array After Applying Operation (数组的最大美丽值)
You are given a 0-indexed integer array nums and a non-negative integer k. In one operation you may choose an index and replace nu...
Take K of Each Character From Left and Right (每种字符至少取 K 个)
You are given a string s consisting of the characters a, b and c, and a non-negative integer k. Each minute you may take one chara...
Count of Substrings Containing Every Vowel and K Consonants II (元音辅音字符串计数 II)
You are given a string word and a non-negative integer k. Return the number of substrings that contain every vowel (a, e, i, o, u)...
Minimum Window Substring (最小覆盖子串)
Given two strings s and t, return the minimum window substring of s that contains every character of t (with multiplicity). If no ...
Sliding Window Maximum (滑动窗口最大值)
You are given an array nums and a window size k. A sliding window of size k moves from the left to the right of the array. Return ...
Subarrays with K Different Integers (K 个不同整数的子数组)
Given an integer array nums and an integer k, return the number of good subarrays: contiguous subarrays with exactly k different i...
Minimum Number of Operations to Make Array Continuous (使数组连续的最少操作数)
Given an integer array nums, you may increment or decrement elements arbitrarily. The array is continuous if all elements are dist...
Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit (绝对差不超过限制的最长连续子数组)
Given an array of integers nums and an integer limit, return the size of the longest subarray such that the absolute difference be...
Smallest Range Covering Elements from K Lists (最小区间)
You are given k sorted lists of integers in nums. Find the smallest range [a, b] such that at least one number from each list lies...
Binary Search (二分查找)
Given a sorted array of integers nums and an integer target, return the index of target if it exists, otherwise -1. Constraints: 1...
Search Insert Position (搜索插入位置)
Given a sorted array of distinct integers nums and a target, return the index where the target is, or where it should be inserted ...
Guess Number Higher or Lower (猜数字大小)
This is an interactive problem. A number is picked from 1 to n. You call guess(num) which returns -1 if your guess is higher, 1 if...
Arranging Coins (排列硬币)
You have n coins and want to build a staircase where the i-th row has exactly i coins. Return the number of complete rows. Constra...
Valid Perfect Square (有效的完全平方数)
Given a positive integer num, return true if it is a perfect square, i.e. it equals k * k for some integer k. You must not use any...