面试场景
高频考察问题建模、边界条件与口头表达的清晰度。
常见误区
只背模板不解释为什么,容易在追问里失分。
练习策略
每轮练 3-5 题,固定复盘复杂度和可替代解法。
推荐练习顺序
长度最小的子数组
Find the minimal length of a subarray whose sum is greater than or equal to the target using efficient algorithms.
除了自身以外数组的乘积
Solve the 'Product of Array Except Self' problem by calculating the product of all elements except self for each index e…
区域和检索 - 数组不可变
The Range Sum Query - Immutable problem involves implementing a data structure to handle range sum queries efficiently.
二维区域和检索 - 矩阵不可变
Design a 2D matrix class that efficiently handles sum queries with O(1) time complexity using a prefix sum approach.
矩形区域不超过 K 的最大数值和
Solve the "Max Sum of Rectangle No Larger Than K" problem using binary search over the valid sum space to optimize space…
分割数组的最大值
Solve the 'Split Array Largest Sum' problem by minimizing the largest sum across k subarrays using dynamic programming a…
非重叠矩形中的随机点
Design an algorithm to pick random points within non-overlapping rectangles using binary search and reservoir sampling.
连续的子数组和
Identify if any continuous subarray sums to a multiple of k using prefix sums and hash table tracking efficiently.
连续数组
Find the maximum length contiguous subarray with equal numbers of 0s and 1s using array scanning and hash lookup efficie…
按权重随机选择
Random Pick with Weight requires implementing a probabilistic index picker using prefix sums and binary search efficient…
和为 K 的子数组
Count the total number of contiguous subarrays in an integer array that sum exactly to a target value k using optimized …
三个无重叠子数组的最大和
Maximize the sum of three non-overlapping subarrays with length k in an integer array using dynamic programming.
乘积小于 K 的子数组
Count subarrays with a product strictly less than a given value k using efficient algorithms like binary search and slid…
寻找数组的中心下标
Find the pivot index in an array where the sums of elements on both sides are equal using array and prefix sum technique…
我的日程安排表 II
Implement a calendar that allows double bookings but prevents triple bookings, managing overlapping intervals efficientl…
我的日程安排表 III
Implement My Calendar III to track maximum overlapping events efficiently using binary search and segment tree technique…
得分最高的最小轮调
Find the smallest rotation index with the highest score using array and prefix sum techniques.
最大平均值和的分组
Maximize the sum of averages by partitioning an integer array into at most k contiguous subarrays using dynamic programm…
字母移位
Given a string and a shift array, shift the first i+1 letters of the string as specified in the array.
和至少为 K 的最短子数组
Find the shortest subarray with a sum of at least k using binary search and sliding window techniques.
DI 序列的有效排列
The problem asks to find the number of valid permutations for a given DI sequence string using dynamic programming and s…
和相同的二元子数组
Count all contiguous subarrays in a binary array whose elements sum exactly to a given goal using prefix sums efficientl…
和可被 K 整除的子数组
Count the number of subarrays whose sum is divisible by a given integer k using array scanning and hash lookup.
K 连续位的最小翻转次数
Determine the minimum number of k-length consecutive bit flips needed to convert all zeros to ones in a binary array eff…
合并石头的最低成本
Minimize the cost to merge stones with k consecutive piles using dynamic programming to achieve the optimal solution.
最大连续1的个数 III
Find the longest consecutive ones in a binary array by optimally flipping at most k zeros using sliding window technique…
元素和为目标值的子矩阵数量
Count all non-empty submatrices in a given matrix whose elements sum exactly to the target using efficient scanning tech…
拼车
Determine if a car can handle multiple trips without exceeding its capacity using array sorting and event simulation tec…
航班预订统计
Solve Corporate Flight Bookings by marking range changes once, then building final seat totals with a single prefix sum …
表现良好的最长时间段
The Longest Well-Performing Interval problem challenges you to find the longest subarray where tiring days exceed non-ti…
石子游戏 II
Stone Game II is a dynamic programming problem where Alice and Bob alternate taking stones from piles to maximize their …
构建回文串检测
Given a string and queries, determine if a substring can be rearranged and modified to form a palindrome.
尽可能使字符串相等
Optimize substring transformations using a binary search approach to maximize the change within a budget.
统计「优美子数组」
The problem requires counting subarrays with exactly k odd numbers using an efficient array scanning approach.
元素和小于等于阈值的正方形的最大边长
This problem challenges you to find the largest square in a matrix with a sum below a given threshold using binary searc…
子数组异或查询
Compute XOR results for multiple subarray queries using efficient prefix XOR to reduce repeated computation overhead in …
矩阵区域和
Compute a matrix where each cell contains the sum of all elements within k-distance blocks using prefix sums efficiently…
最后 K 个数的乘积
Design a data structure to efficiently return the product of the last k numbers in a dynamic integer stream using prefix…
每个元音包含偶数次的最长子字符串
Find the longest substring with even counts of vowels using bitmasking and hash tables.
逐步求和得到正数的最小值
Find the minimum starting value to ensure the step-by-step sum of an array is always at least 1.
生成数组
This problem asks to build an array where the maximum element is found using exactly K comparisons, with dynamic program…
分割字符串的最大得分
Find the optimal split point in a binary string to maximize zeros on the left and ones on the right efficiently.
可获得的最大点数
Maximize your score by selecting k cards from the beginning or end of the array using a sliding window approach.
形成两个异或相等数组的三元组数目
Efficiently count all triplets in an array where two subarrays formed by splitting have equal XOR using array scanning a…
切披萨的方案数
This problem challenges you to determine the number of valid ways to cut a pizza into pieces with apples using dynamic p…
一维数组的动态和
Calculate the running sum of a given 1D array by updating each element to the sum of itself and all previous elements.
子数组和排序后的区间和
Compute the sum of sorted subarray sums efficiently using binary search over valid sum ranges and prefix sum accumulatio…
和为奇数的子数组数目
Count the number of subarrays with an odd sum using dynamic programming and prefix sum techniques.
和为目标值且不重叠的非空子数组的最大数目
Find the maximum number of non-overlapping subarrays that sum to a given target using efficient scanning and hash lookup…
所有奇数长度子数组的和
Calculate the sum of all odd-length subarrays in a given integer array using efficient array and math strategies.
所有排列中的最大和
Maximize the total sum of requests on nums by greedily assigning larger numbers to most frequently requested indices.
使数组和能被 P 整除
Determine the minimum-length subarray to remove so the remaining array sum is divisible by a given integer p efficiently…
将 x 减到 0 的最小操作数
Find the minimum number of operations to reduce a value x to zero by removing elements from an array.
生成平衡数组的方案数
Solve Ways to Make a Fair Array by tracking parity sums before and after each removal with prefix-sum style accounting.
使数组互补的最少操作次数
Find the minimum moves to make an array complementary by analyzing paired sums and using hash lookups for efficiency.
有序数组中差绝对值之和
Calculate the sum of absolute differences between each element and others in a sorted array efficiently.
从仓库到码头运输箱子
Optimize the minimum number of trips to deliver boxes to ports under strict ship constraints using dynamic programming t…
得到连续 K 个 1 的最少相邻交换次数
Find the minimum number of adjacent swaps to gather k consecutive ones in a binary array using sliding window logic.
将数组分成三个子数组的方案数
The problem requires finding the number of ways to split an array into three subarrays where each split meets a certain …
找到最高海拔
Find the highest altitude after a series of altitude changes during a road trip using prefix sum technique.
满足三条件之一需改变的最少字符数
This problem asks for the minimum operations to change two strings so that one of three conditions is met.
找出第 K 大的异或坐标值
Compute the kth largest XOR coordinate in a 2D matrix using prefix sums, bit manipulation, and optimized selection techn…
你能在你最喜欢的那天吃到你最喜欢的糖果吗?
Determine if you can eat a candy of your favorite type on a specific day, given daily limits and candy availability.
移动所有球到每个盒子所需的最小操作数
Solve the problem of finding the minimum operations to move balls to each box using an efficient approach with arrays an…
每个查询的最大异或值
Find the maximum XOR for each query based on a sorted array and bit manipulation.
最高频元素的频数
Maximize the frequency of an element in an array by incrementing at most `k` elements. Use binary search and greedy tech…
人口最多的年份
Find the earliest year with the highest population using an array plus counting approach.
子数组最小乘积的最大值
The problem asks to find the maximum min-product of any non-empty subarray of nums.
向下取整数对和
The problem asks to calculate the sum of floor divisions for all pairs in a given integer array, using an efficient meth…
跳跃游戏 VII
The problem asks to determine if we can reach the last index of a binary string, with a set range of jumps between indic…
石子游戏 VIII
Stone Game VIII requires calculating maximum score difference using state transition dynamic programming on prefix sums …
矩阵中最大的三个菱形和
Find the three largest distinct rhombus sums from a given grid using array and math techniques.
装包裹的最小浪费空间
Minimize the wasted space when packaging items into boxes, considering package and box size constraints.
检查是否区域内所有整数都被覆盖
Check if all integers in the range [left, right] are covered by intervals in a given set of ranges.
找到需要补充粉笔的学生编号
Identify the first student who will run out of chalk using a simulation with prefix sums and binary search.
最大的幻方
Find the side length of the largest magic square in a matrix where row, column, and diagonal sums are equal.
最美子字符串的数目
Count the number of wonderful non-empty substrings of a given string based on frequency conditions of characters.
长度为 3 的不同回文子序列
Count all unique length-3 palindromic subsequences in a string efficiently using hash tables and character positions.
描述绘画结果
Solve the problem of describing a painted segment with mixed colors using array scanning and hash table lookups.
找到数组的中间位置
Find the smallest middle index where the sum of elements on the left equals the sum on the right using prefix sums effic…
网格游戏
Solve the Grid Game problem by optimizing the movement of two robots on a 2D matrix grid.
考试的最大困扰度
Maximize the Confusion of an Exam requires adjusting at most k answers to create the longest consecutive true or false s…
分割数组的最多方案数
Determine the maximum number of ways to split an array into equal sums using at most one element change, leveraging pref…
蜡烛之间的盘子
Determine the number of plates between candles in a given substring using binary search and prefix sum techniques.
适合野炊的日子
Find good days to rob the bank by identifying days with non-increasing and non-decreasing guard counts using dynamic pro…
摘水果
Compute the maximum fruits collectable on an infinite line by moving at most k steps from a start position efficiently.
相同元素的间隔之和
Solve the problem of calculating intervals between identical elements using array scanning and hash lookup.
用邮票贴满网格图
Determine if a binary grid can be fully covered using fixed-size stamps by applying a greedy placement and validation st…
统计隐藏数组数目
Given a sequence of differences, count how many hidden sequences fit within a range using an array and prefix sum approa…
拿出最少数目的魔法豆
Determine the minimum beans to remove so all remaining non-empty bags have equal beans using a greedy approach.
字符串中最多数目的子序列
Maximize the number of subsequences by optimally adding a character to a given string to match a specified pattern.
用地毯覆盖后的最少白色砖块
Find the minimum number of white tiles visible after optimally placing carpets using state transition dynamic programmin…
从栈中取出 K 个硬币的最大面值和
Optimize coin selection across multiple piles using state transition dynamic programming to achieve the maximum wallet v…
选择建筑的方案数
Solve Number of Ways to Select Buildings by counting alternating 3-building patterns with state transitions over the bin…
花园的最大总美丽值
Determine the maximum total beauty of gardens by strategically planting flowers using binary search over achievable flow…
转角路径的乘积中最多能有几个尾随零
Find the maximum trailing zeros in the product of a cornered path within a 2D grid.
花期内花的数目
Find the number of flowers in full bloom at the given times for a list of people.
最小平均差
Find the index with the minimum average difference in an array using prefix sums.
分割数组的方案数
Count all valid ways to split a 0-indexed integer array into two non-empty parts using array plus prefix sum logic effic…
毯子覆盖的最多白色砖块数
Solve Maximum White Tiles Covered by a Carpet by sorting intervals, checking optimal carpet starts, and counting full pl…
巫师的总力量和
The Sum of Total Strength of Wizards problem asks for the sum of the total strengths of all contiguous subarrays of wiza…
统计得分小于 K 的子数组数目
Count all non-empty subarrays whose score, defined as sum times length, is strictly less than a given integer k efficien…
字母移位 II
Shift letters in a string using a sequence of range-based forward or backward operations efficiently with prefix sums.
删除操作后的最大子段和
Calculate the maximum segment sum after sequential removals using array plus union find for efficient merging of segment…
和有限的最长子序列
Find the maximum size of a subsequence from nums with a sum less than or equal to each query value.
收集垃圾的最少总时间
This problem asks you to find the minimum amount of time needed to collect all garbage in a city, focusing on array and …
预算内的最多机器人数目
Determine the maximum number of consecutive robots you can operate without exceeding a given budget using efficient bina…
将区间分为最少组数
Determine the minimum number of non-overlapping groups for a set of intervals using precise two-pointer scanning logic.
找到所有好下标
Identify all indices in an array where the k-length prefix is non-increasing and the k-length suffix is non-decreasing.
沙漏的最大总和
Calculate the maximum sum of an hourglass in a 2D matrix using array traversal and submatrix evaluation techniques effic…
二的幂数组中查询范围内的乘积
The Range Product Queries of Powers problem requires calculating the product of powers of 2 for a range of queries on a …
最小化数组中的最大值
Minimize Maximum of Array involves finding the smallest possible maximum value after applying a series of operations on …
使数组相等的最小开销
Find the minimum cost to make all elements of an array equal by using binary search over valid answers.
商店的最少代价
Determine the earliest closing hour of a shop to minimize penalty using a string of customer visits and prefix sums.
找出中枢整数
Find the Pivot Integer problem challenges you to identify an integer x that balances prefix sums on both sides.
统计中位数为 K 的子数组
Count the number of subarrays in a given array with median equal to a specified value k.
最大化城市的最小电量
Determine the maximum minimum power a city can achieve by strategically adding power stations using binary search and pr…
子矩阵元素加 1
Increment Submatrices by One focuses on efficiently updating submatrices using row-wise prefix sums in an n by n matrix.
统计上升四元组
Given a permutation of numbers, count the number of increasing quadruplets using dynamic programming.
统计范围内的元音字符串数
Count the number of strings that start and end with a vowel in given ranges within an array of words.
左右元素和的差值
Compute absolute differences between left and right cumulative sums for each element in an integer array efficiently.
重排数组以得到最大前缀分数
Maximize the number of positive prefix sums by rearranging an integer array using a greedy, order-focused strategy.
统计美丽子数组数目
Count the Number of Beautiful Subarrays is a Medium-level problem involving array scanning and hash table lookup to find…
使数组元素全部相等的最少操作次数
Find the minimum number of operations to make all elements in an array equal for each query.
等值距离和
In this problem, you calculate an array where each element is the sum of absolute differences of indices for equal value…
一个数组所有前缀的分数
Compute the score of each prefix in an array using conversion rules while tracking the maximum efficiently for prefix su…
最大或值
Maximize the bitwise OR of an array by applying at most k multiplication operations on selected elements.
英雄的力量
Calculate the total power of all non-empty hero groups using state transition dynamic programming efficiently with sorti…
移动机器人
Calculate total distances between robots moving on a number line while accounting for collisions using array plus braint…
使数组中的所有元素都等于零
Determine if all elements in a given array can be reduced to zero using repeated k-length prefix operations efficiently.
统计趣味子数组的数目
Count all subarrays where the number of elements satisfying a modulo condition equals a target k using efficient prefix …
与车相交的点
Count covered integer points by merging overlapping car intervals or marking visited positions on the number line.
无限数组的最短子数组
Find the shortest subarray in an infinite array that sums to a given target using array scanning and hash lookup.
构造乘积矩阵
Solve the "Construct Product Matrix" problem by calculating the product of elements in 2D matrices without division.
统计美丽子字符串 I
Given a string and a value k, count the number of beautiful substrings where vowels * consonants % k == 0.
统计美丽子字符串 II
Count Beautiful Substrings II focuses on finding beautiful substrings with hash tables and number theory techniques.
执行操作使频率分数最大
Maximize the frequency score by applying up to k operations on a sorted array using binary search over valid answer spac…
找到最大周长的多边形
Determine the largest perimeter polygon from a set of side lengths using a greedy approach with invariant validation che…
回文串重新排列查询
Given a string and queries, check if rearranging specified substrings can make the string a palindrome.
按距离统计房屋对数目 I
Determine the number of house pairs at each street distance using graph traversal and breadth-first search efficiently.
按距离统计房屋对数目 II
Count the Number of Houses at a Certain Distance II is a graph problem that requires efficient pair counting with an add…
最大好子数组和
Find the maximum sum of any subarray where the first and last elements differ by exactly k using efficient array scannin…
边界上的蚂蚁
Solve the problem of counting how often an ant returns to a boundary based on the steps described in the input array.
元素和小于等于 k 的子矩阵的数目
Count all submatrices including the top-left element with sum less than k using array and matrix prefix sum strategies.
K 个不相交子数组的最大能量值
Solve Maximum Strength of K Disjoint Subarrays with dynamic programming that tracks segment state, sign changes, and wei…
拾起 K 个 1 需要的最少行动次数
Find the minimum number of moves to pick exactly k ones from a binary array, considering a constraint on changes.
得到更多分数的最少关卡数目
Determine the minimum number of levels Alice must play in a binary game array to secure more points than Bob using prefi…
找出所有稳定的二进制数组 I
Find all stable binary arrays of a given number of 0's, 1's, and limit using dynamic programming and state transitions.
找出所有稳定的二进制数组 II
Compute the number of stable binary arrays using state transition dynamic programming with exact zero, one, and limit co…
从魔法师身上吸取的最大能量
Maximize your energy by strategically jumping through magicians using array and prefix sum techniques for optimal path c…
特殊数组 II
Determine whether each subarray meets the special condition of alternating parity for all adjacent elements efficiently …
K 秒后第 N 个元素的值
Solve for the N-th value after K seconds by simulating array updates and using prefix sum techniques.
使二进制数组全部等于 1 的最少操作次数 I
Find the minimum number of operations to make all elements of a binary array equal to one using sliding window and state…
统计 X 和 Y 频数相等的子矩阵数量
Count the number of submatrices with equal frequency of 'X' and 'Y' in a 2D character grid.
使差值相等的最少数组改动次数
Minimize changes to make array differences equal by replacing elements within a given range.
网格图操作后的最大分数
Maximize your score by choosing the optimal sequence of column operations on a grid using dynamic programming transition…
单调数组对的数目 I
Compute the number of monotonic pairs in an integer array using state transition dynamic programming efficiently.
单调数组对的数目 II
This problem involves finding the count of monotonic pairs in an array using dynamic programming and combinatorics techn…
统计满足 K 约束的子字符串数量 II
Count Substrings That Satisfy K-Constraint II requires finding valid substrings in a binary string based on a k-constrai…
查询排序后的最大公约数
Solve the Sorted GCD Pair Queries problem by efficiently counting and locating GCDs of all array pairs using hash mappin…
找到初始输入字符串 II
Calculate how many potential original strings Alice might have intended to type, considering her clumsy typing behavior.
执行操作后元素的最高频率 I
Maximize the frequency of an element in an array after performing a series of operations to find the best possible resul…
执行操作后元素的最高频率 II
Determine the maximum frequency of any element after performing limited operations using binary search and sliding windo…
使数组元素等于零
Learn how to transform an integer array to zeros using simulation and directional selection efficiently and reliably.
零数组变换 I
Transform the given integer array into a zero array using range operations, focusing on prefix sum optimization and care…
零数组变换 II
Zero Array Transformation II requires determining the minimum query sequence to convert all array elements to zero using…
两个字符串的切换距离
Find the minimum cost of transforming one string into another, considering operations between characters.
零数组变换 III
Zero Array Transformation III requires removing the minimum number of queries to make all elements zero using greedy val…
最小正和子数组
Find the minimum sum of any subarray of size between l and r with a positive total using efficient sliding window logic.
长度可被 K 整除的子数组的最大元素和
Find the maximum sum of a subarray where the length of the subarray is divisible by k.
收集连续 K 个袋子可以获得的最多硬币数量
Solve the problem of maximizing coins from selecting k consecutive bags, using binary search and sliding window techniqu…
最长特殊路径
Compute the longest downward path in a tree with unique node values using DFS, hash lookup, and careful array scanning.
变长子数组求和
Calculate the total sum of all elements in subarrays defined for each index in an array, using the array plus prefix sum…
统计元素和差值为偶数的分区方案
Count the number of partitions with an even sum difference from an array of integers.
子数组操作后的最大频率
Determine the maximum frequency of a target value k after applying one subarray addition operation efficiently using arr…
奇偶频次间的最大差值 II
Find the maximum difference between even and odd character frequencies in substrings using sliding window updates effici…
长度至少为 M 的 K 个子数组之和
Maximize the sum of k non-overlapping subarrays of at least length m using dynamic programming and prefix sums efficient…
删除一个冲突对后最大子数组数目
Maximize the count of subarrays after removing one conflicting pair using array traversal and segment tree logic efficie…
最长特殊路径 II
Find the longest downward path in a tree where node values are mostly distinct, allowing one repeat, using array scannin…
酿造药水需要的最少总时间
This problem involves calculating the minimum time required for wizards to brew potions based on their skills and mana u…
将数组分割为子数组的最小代价
Optimize array splits with dynamic programming to minimize costs for the Minimum Cost to Divide Array Into Subarrays pro…
合并得到最小旅行时间
Minimize the total travel time by merging road signs, using dynamic programming to manage state transitions efficiently.
等和矩阵分割 I
Determine if an m x n matrix grid can be split into two non-empty sections with equal sums by making a single horizontal…
等和矩阵分割 II
Determine if a matrix can be partitioned into two sections with an equal sum using a single cut.
统计极差最大为 K 的分割方式数
Count the number of valid ways to partition an array into contiguous segments where max-min difference is at most k.
划分数组得到最小 XOR
Partition an integer array into k subarrays to minimize the maximum XOR using state transition dynamic programming effic…