面试场景
高频考察问题建模、边界条件与口头表达的清晰度。
常见误区
只背模板不解释为什么,容易在追问里失分。
练习策略
每轮练 3-5 题,固定复盘复杂度和可替代解法。
推荐练习顺序
最长回文子串
Find the longest contiguous palindromic substring in a given string using dynamic programming and two-pointer expansion …
盛最多水的容器
Find two vertical lines that can form a container with the most water in a given array of heights.
三数之和
Given an integer array, return all unique triplets where the sum is zero using two-pointer scanning with careful duplica…
最接近的三数之和
Find the sum of three integers in an array that is closest to a given target using two-pointer scanning.
四数之和
The 4Sum problem requires finding all unique quadruplets in an array that sum to a specific target value.
删除链表的倒数第 N 个结点
Remove the nth node from the end of a linked list using a two-pointer approach to solve efficiently.
删除有序数组中的重复项
Learn how to remove duplicates from a sorted array in-place using two-pointer scanning while preserving element order.
移除元素
Remove Element challenges you to remove a value from an array in-place using efficient two-pointer scanning and tracking…
找出字符串中第一个匹配项的下标
Locate the first occurrence of a substring within a string using a two-pointer scanning strategy and invariant tracking …
下一个排列
Next Permutation is a medium-difficulty problem focusing on generating the next lexicographically greater permutation of…
接雨水
Calculate the total trapped rain water using the elevation map array, leveraging dynamic programming and two-pointer pat…
旋转链表
Rotate a singly linked list to the right by k positions using careful pointer manipulation and two-pointer traversal tec…
颜色分类
Sort Colors requires in-place reordering of an array using a two-pointer scanning strategy to group 0s, 1s, and 2s effic…
删除有序数组中的重复项 II
Solve the problem of removing duplicates from a sorted array in-place, ensuring each element appears at most twice, usin…
删除排序链表中的重复元素 II
Remove duplicates from a sorted linked list, leaving only distinct values, and return the modified list in sorted order.
分隔链表
Partition a linked list such that all nodes less than x come before nodes greater than or equal to x while preserving re…
合并两个有序数组
Merge two sorted arrays into the first array in non-decreasing order, using a two-pointer approach.
验证回文串
Check if a given string is a valid palindrome by using two-pointer scanning and invariant tracking techniques.
环形链表
Determine if a given linked list contains a cycle using pointer manipulation or hashing, focusing on detecting repeated …
环形链表 II
Identify the start of a cycle in a linked list using pointer manipulation, efficiently handling edge cases without modif…
重排链表
Reorder List requires careful pointer manipulation in a singly linked list to interleave nodes from the ends without alt…
排序链表
Sort List requires sorting a singly linked list efficiently using pointer manipulation and merge sort for optimal perfor…
反转字符串中的单词
Reverse Words in a String requires reordering words using precise two-pointer scanning with careful space handling for e…
相交链表
Given two linked lists, find the node where they intersect or return null if they do not.
比较版本号
Compare two version numbers by checking their individual revisions, considering missing revisions as zero, using a two-p…
两数之和 II - 输入有序数组
Solve the Two Sum II problem efficiently using binary search over a valid answer space in a sorted array.
轮转数组
Rotate Array challenges you to shift elements right by k steps using precise two-pointer scanning and invariant tracking…
快乐数
Determine if a number is happy by repeatedly summing squares of digits using two-pointer scanning to detect cycles effic…
回文链表
Solve Palindrome Linked List by finding the midpoint, reversing the second half, and comparing mirrored nodes in linear …
移动零
Move all zeros in an array to the end while preserving the order of non-zero elements using efficient in-place operation…
寻找重复数
The problem involves finding the duplicate number in an array of integers, using a binary search approach over the valid…
数据流的中位数
Implement a MedianFinder class that supports adding numbers and finding the median from a data stream.
拼接最大数
Create Maximum Number involves merging digits from two arrays while preserving order, maximizing the resulting number.
反转字符串
Reverse a character array in-place using a two-pointer scanning technique, ensuring minimal memory and correct index swa…
反转字符串中的元音字母
Reverse Vowels of a String uses a two-pointer approach to reverse the vowels in a string while leaving the consonants in…
两个数组的交集
Find the intersection of two arrays while ensuring unique elements using efficient array scanning and hash lookups.
两个数组的交集 II
Find the intersection of two arrays, accounting for multiple occurrences of the same number.
判断子序列
Determine if one string is a subsequence of another using state transition dynamic programming for accurate character ma…
压缩字符串
Compress a character array in-place by converting consecutive repeated characters into counts using two-pointer scanning…
分发饼干
Maximize content children by assigning at most one cookie per child using two-pointer scanning and greedy sorting techni…
环形数组是否存在循环
Detect whether a circular array contains a loop of consistent direction using efficient array scanning and hash lookup t…
供暖器
Determine the minimum heater radius to cover all houses using a binary search over potential radius values efficiently.
神奇字符串
Count the number of '1's in the first n characters of a magical string using two-pointer scanning and invariant tracking…
最长特殊序列 II
Find the longest string in an array that is not a subsequence of any other string, using array scanning and hash checks …
通过删除字母匹配到字典里最长单词
Find the longest word in the dictionary that can be formed by deleting characters from a string, using two-pointer scann…
数组中的 k-diff 数对
Solve K-diff Pairs in an Array by counting unique differences with a hash map or sorted two-pointer sweep.
反转字符串 II
Reverse String II requires reversing segments of a string using two-pointer scanning while tracking invariants carefully…
下一个更大元素 III
Find the next greater integer using the same digits as a given number with precise two-pointer scanning and invariant tr…
反转字符串中的单词 III
Reverse Words in a String III involves reversing each word in a sentence using the two-pointer technique.
字符串的排列
Check if a string contains a permutation of another string using two-pointer scanning and hash table techniques.
最短无序连续子数组
Find the shortest unsorted continuous subarray that, if sorted, would sort the entire array.
有效三角形的个数
Count all triplets in an integer array that satisfy the triangle inequality to form valid triangles efficiently using so…
平方数之和
Given a non-negative integer c, determine if there are two integers whose squares sum to c.
回文子串
Count all palindromic substrings in a given string using state transition dynamic programming for efficient evaluation.
两数之和 IV - 输入二叉搜索树
Determine if a binary search tree contains two nodes whose values sum to a target using efficient traversal and state tr…
找到 K 个最接近的元素
Identify the k integers closest to a target x in a sorted array using binary search and two-pointer strategies efficient…
验证回文串 II
Check if a string can become a palindrome by deleting at most one character using two-pointer scanning and invariant tra…
计数二进制子串
Count Binary Substrings solves for the number of valid substrings with equal 0's and 1's, grouped consecutively in a bin…
找出第 K 小的数对距离
Solve Find K-th Smallest Pair Distance by sorting nums, then binary searching the distance and counting valid pairs with…
划分字母区间
Partition a string into maximal parts so that each letter appears in only one segment, using two-pointer scanning.
在 LR 字符串中交换相邻字符
Transform one string into another by swapping adjacent 'L' and 'R' characters in a sequence of moves.
第 K 个最小的质数分数
Find the k-th smallest fraction from a sorted array of unique primes using a binary search over the answer space.
区间子数组个数
Count the number of contiguous subarrays with a bounded maximum value using a two-pointer approach.
情感丰富的文字
Expressive Words challenges you to determine if a word can be transformed into a given string by extending groups of rep…
字符的最短距离
Compute the minimum distance from each character in a string to a target character using efficient scanning techniques.
适龄的朋友
The Friends Of Appropriate Ages problem involves counting valid friend requests between people based on their ages with …
安排工作以达到最大收益
Assign workers to jobs maximizing total profit using difficulty, profit, and worker arrays efficiently with binary searc…
翻转图像
Flip each row of a binary matrix horizontally and invert its values efficiently using a two-pointer scanning approach.
推多米诺
In the "Push Dominoes" problem, you simulate the falling dominoes based on their initial states and determine their fina…
比较含退格的字符串
Compare two strings after processing backspaces using efficient two-pointer scanning and careful invariant tracking to e…
数组中的最长山脉
Find the length of the longest subarray forming a mountain pattern using state transitions and two-pointer logic efficie…
优势洗牌
Maximize the advantage of nums1 over nums2 using a two-pointer greedy strategy, carefully tracking which elements beat o…
链表的中间结点
Find the middle node of a singly linked list using a two-pointer technique.
救生艇
Find the minimum number of boats required to save all people, using a two-pointer approach for efficient pairing.
按奇偶排序数组
Reorder an integer array so all even numbers come before odd numbers using a precise two-pointer scanning method.
仅仅反转字母
Reverse the characters of a string while skipping non-letter characters using a two-pointer technique.
按奇偶排序数组 II
Sort an array where even numbers appear at even indices and odd numbers appear at odd indices using two-pointer scanning…
三数之和的多种可能
Count all unique triplets in an integer array whose sum equals the target, handling multiplicity efficiently using hashi…
长按键入
Check if a typed string could result from long pressing characters while typing a given name using a two-pointer scan.
增减字符串匹配
Reconstruct a permutation from a DI string using two-pointer scanning, carefully tracking the increasing and decreasing …
令牌放置
Maximize your score in the Bag of Tokens problem by strategically playing tokens with two-pointer scanning and greedy te…
最大宽度坡
Find the maximum width of a ramp where nums[i] <= nums[j] for i < j using a two-pointer approach.
煎饼排序
Sort an array using pancake flips, leveraging two-pointer scanning and invariant tracking to iteratively position the la…
有序数组的平方
The problem involves squaring elements of a sorted array and returning the squares in non-decreasing order.
区间列表的交集
This problem requires finding the intersection of two lists of intervals using a two-pointer technique with invariant tr…
驼峰式匹配
Camelcase Matching is a medium difficulty problem where you match queries to a given pattern by inserting lowercase lett…
最长字符串链
Find the longest word chain by scanning arrays and using hash lookups to efficiently track predecessor-successor sequenc…
复写零
Duplicate each zero in a fixed-length array in place, shifting elements right using a two-pointer scanning approach effi…
段式回文
Solve the "Longest Chunked Palindrome Decomposition" problem by using dynamic programming and string manipulation techni…
按字典序排在最后的子串
Identify the lexicographically last substring in a string using two-pointer scanning with invariant tracking efficiently…
找出给定方程的正整数解
Determine all positive integer pairs that satisfy a hidden monotonic function for a given target using binary search ove…
删除回文子序列
This problem challenges you to remove palindromic subsequences from a string with a minimum number of steps using two-po…
检查整数及其两倍数是否存在
Solve Check If N and Its Double Exist by scanning once and checking doubles or halves in a hash set.
两个数组间的距离值
Calculate the distance value between two integer arrays by determining how many elements in arr1 don't have a close coun…
检查单词是否为句中其他单词的前缀
Determine the first word in a sentence where a given searchWord is a prefix using two-pointer scanning with string match…
数组中的 k 个最强值
Identify the k strongest values in an array using two-pointer scanning and careful tracking of the array's centre value.
满足条件的子序列数目
Count all non-empty subsequences in an integer array where the sum of the minimum and maximum elements is at most a targ…
子数组和排序后的区间和
Compute the sum of sorted subarray sums efficiently using binary search over valid sum ranges and prefix sum accumulatio…
最大得分
Find the maximum possible score from two sorted arrays with a dynamic programming approach, leveraging partitioning and …
删除最短的子数组使剩余数组有序
Find the shortest subarray to remove in order to make an array non-decreasing using binary search and two-pointer techni…
数的平方等于两数乘积的方法数
Find the number of triplets where the square of a number equals the product of two others, utilizing array scanning and …
分割两个字符串得到回文串
Determine if splitting two equal-length strings at a common index can form a palindrome using two-pointer scanning techn…
K 和数对的最大数目
Max Number of K-Sum Pairs is a problem involving counting disjoint pairs with a given sum k in an array.
检查边长度限制的路径是否存在
Solve the problem of checking if there exists a path between two nodes under edge length constraints using efficient tec…
将数组分成三个子数组的方案数
The problem requires finding the number of ways to split an array into three subarrays where each split meets a certain …
交换链表中的节点
Swap nodes in a linked list using linked-list pointer manipulation and two pointers to solve this medium difficulty prob…
删除字符串两端相同字符后的最短长度
Minimize string length by deleting similar characters from both ends repeatedly using a two-pointer technique.
构造字典序最大的合并字符串
Construct the lexicographically largest merge from two strings using a two-pointer greedy scanning approach efficiently.
最接近目标值的子序列和
Find the minimum absolute difference between a target goal and any subsequence sum using optimized dynamic programming a…
通过连接另一个数组的子数组得到一个数组
Determine if you can sequentially select disjoint subarrays from nums matching each group in order using two-pointer sca…
交替合并字符串
Merge two strings alternately, starting with the first string, and append extra characters when one string is longer.
统计点对的数目
Given a graph with nodes and edges, count pairs of nodes where the degree sum exceeds a given threshold for each query.
好子数组的最大分数
Maximize the score of a good subarray using binary search to explore the valid answer space with a focus on two-pointer …
句子相似性 III
Sentence Similarity III asks if one sentence can be transformed into another by inserting a sentence inside it.
邻位交换的最小次数
Find the minimum number of adjacent swaps to reach the kth smallest wonderful integer from a given number string.
下标对中的最大距离
Find the maximum distance between a pair of values in two non-increasing integer arrays using binary search.
旋转盒子
Rotate a box represented by a character matrix, letting stones fall under gravity using precise two-pointer scanning and…
数组中最大数对和的最小值
Minimize the maximum pair sum in an array by optimally pairing its elements.
可移除字符的最大数目
Use binary search and a subsequence check to find the largest removable prefix that still keeps p inside s.
检查字符串是否为数组前缀
Determine if a string is a prefix of an array by concatenating initial elements, using two-pointer scanning efficiently.
使字符串平衡的最小交换次数
Determine the minimum swaps to balance a bracket string using two-pointer scanning with invariant tracking efficiently.
反转单词前缀
Reverse the prefix of a string starting from index 0 to the first occurrence of a given character.
将数组分成两个数组并最小化数组和的差
Partition an integer array into two equal halves to minimize the absolute difference of their sums using dynamic program…
你可以安排的最多任务数目
Maximize the number of tasks that can be completed by efficiently using workers and magical pills.
删除链表的中间节点
Efficiently remove the middle node from a linked list using two-pointer techniques and careful pointer updates to mainta…
给植物浇水 II
Simulate watering a row of plants with Alice and Bob using two-pointer scanning, tracking refills precisely for each ste…
找出数组中的第一个回文字符串
Return the first palindromic string from an array of words or an empty string if none exists.
向字符串添加空格
Learn to efficiently insert spaces in a string using two-pointer scanning with invariant tracking in linear time.
还原原数组
Recover the Original Array helps you understand how to reverse-engineer an array from two subsets using array scanning a…
链表最大孪生和
Find the maximum twin sum in a linked list by manipulating pointers efficiently and leveraging stack or reversal techniq…
按符号重排数组
Rearrange an array by alternating positive and negative integers using a two-pointer approach with invariant tracking.
根据给定数字划分数组
Rearrange an array around a pivot while maintaining relative order using a two-pointer scanning approach efficiently.
得到回文串的最少操作次数
The problem challenges you to find the minimum number of adjacent swaps to make a string a palindrome.
找出数组中的所有 K 近邻下标
Identify all indices in an array that are within k distance of elements equal to the given key using two-pointer scannin…
花园的最大总美丽值
Determine the maximum total beauty of gardens by strategically planting flowers using binary search over achievable flow…
咒语和药水的成功对数
Count how many potions pair successfully with each spell using binary search over sorted potion strengths efficiently.
坐上公交的最晚时间
Find the latest time to catch a bus based on departure times, passenger arrivals, and capacity using binary search over …
移动片段得到字符串
Determine if the pieces in start can be moved to form target using two-pointer scanning and strict left-right movement r…
等差三元组的数目
Count the number of arithmetic triplets in a given strictly increasing array with a specified difference.
严格回文的数字
Determine if a number is strictly palindromic in all bases from 2 to n minus 2 using two-pointer scanning and invariant …
将区间分为最少组数
Determine the minimum number of non-overlapping groups for a set of intervals using precise two-pointer scanning logic.
运动员和训练师的最大匹配数
Maximize the number of valid player-trainer matchings using two-pointer scanning and careful sorting strategy.
与对应负数同时存在的最大正整数
Find the largest positive integer in an array such that its negative counterpart also exists.
对数组执行操作
Transform an array by applying adjacent doubling operations and shifting zeros efficiently using two-pointer scanning te…
雇佣 K 位工人的总代价
Optimize the total cost of hiring exactly k workers using a two-pointer approach with invariant tracking and priority qu…
不同的平均值数目
Calculate the number of unique averages formed by repeatedly pairing smallest and largest elements efficiently using has…
不重叠回文子字符串的最大数目
Find the maximum number of non-overlapping palindromic substrings of at least length k in a string using dynamic program…
追加字符以获得子序列
Determine the minimum characters to append to s so t becomes a subsequence using efficient two-pointer scanning techniqu…
划分技能点相等的团队
Divide players into equal skill teams and return the sum of their chemistry, or -1 if impossible.
矩阵查询可获得的最大分数
Solve the Maximum Number of Points From Grid Queries problem using two-pointer scanning and invariant tracking.
最多可以摧毁的敌人城堡数目
Find the maximum number of enemy forts that can be captured by moving your army using two-pointer scanning with invarian…
最小公共值
Find the smallest integer appearing in both sorted arrays efficiently using array scanning and hash-based lookup techniq…
找出数组的串联值
Compute the array concatenation value efficiently using two-pointer scanning while maintaining a running total of concat…
统计公平数对的数目
Efficiently count all fair pairs in an array using sorting and binary search, focusing on the sum range between lower an…
最少得分子序列
Find the minimum score of a string by removing characters from t while maintaining subsequence validity with s.
合并两个二维数组 - 求和法
Merge two 2D arrays by summing values with matching ids using array scanning and hash lookup efficiently.
求出最多标记下标
Maximize marked indices in an array by performing allowed operations, applying binary search to find the optimal count e…
最大化数组的伟大值
Maximize Greatness of an Array requires permuting numbers to exceed original values at most indices efficiently.
字典序最小回文串
Given a string, make it a palindrome with the fewest operations, prioritizing lexicographically smallest result.
统计和小于目标的下标对数目
This problem asks you to count all index pairs in an array whose sum is strictly less than a given target value efficien…
循环增长使字符串子序列等于另一个字符串
Determine if str2 can be made a subsequence of str1 by incrementing characters cyclically using at most one operation.
删除数对后的最小数组长度
This problem involves minimizing the length of a sorted array by repeatedly removing adjacent pairs of equal elements.
找出满足差值条件的下标 I
Find two indices in an array where their difference in both index and value meets specified thresholds.
找出满足差值条件的下标 II
Locate two indices in an array where both index and value differences meet specified thresholds using precise scanning t…
得到 K 个半回文串的最少修改次数
Minimize the number of letter changes to partition a string into k semi-palindromes using dynamic programming and two po…
区分黑球与白球
Solve the "Separate Black and White Balls" problem by swapping adjacent balls to group all black balls to the right with…
统计移除递增子数组的数目 I
Count the number of incremovable subarrays in an array by removing them to create a strictly increasing sequence.
统计移除递增子数组的数目 II
Count the number of incremovable subarrays where removal of the subarray results in a strictly increasing array.
找出数组中的美丽下标 I
Identify all beautiful indices where substring a appears and a nearby substring b exists within distance k efficiently.
找出数组中的美丽下标 II
Find Beautiful Indices in the Given Array II challenges you to use binary search and string matching techniques.
找出与数组相加的整数 II
Given two arrays nums1 and nums2, determine the integer added to nums1 to make it equal to nums2 after removing two elem…
施咒的最大总伤害
Calculate the maximum total damage by selectively casting spells while avoiding adjacent power conflicts using array sca…
最小元素和最大元素的最小平均值
Solve the Minimum Average of Smallest and Largest Elements problem using two-pointer scanning to track averages effectiv…
最少翻转次数使二进制矩阵回文 I
Find the minimum flips to make a binary grid palindromic by scanning with two pointers and tracking symmetry efficiently…
最少翻转次数使二进制矩阵回文 II
The problem asks to flip cells in a binary grid to make its rows and columns palindromic using the minimum number of fli…
字典序最小的合法序列
Determine the lexicographically smallest valid index sequence by using state transition dynamic programming over word1 a…
从原字符串里进行删除操作的最多次数
Determine the maximum number of characters you can remove from source while keeping pattern as a subsequence using array…
从盒子中找出字典序最大的字符串 I
This problem involves finding the lexicographically largest string from a given word using a two-pointer approach.
最短匹配子字符串
Find the shortest substring in a string that matches a pattern with exactly two wildcards efficiently using binary searc…
子字符串连接后的最长回文串 I
Compute the maximum palindrome length by concatenating substrings from two strings using state transition dynamic progra…
子字符串连接后的最长回文串 II
Compute the longest palindrome by concatenating substrings from two strings using state transition dynamic programming e…
子序列首尾元素的最大乘积
Maximize the product of the first and last elements of any subsequence of size m in an integer array.