识别信号
- The candidate demonstrates a clear understanding of binary search over a valid answer space.
- The candidate can explain how the partitioning logic helps in avoiding unnecessary merging of arrays.
- Ask why a standard binary search fails on rotated arrays.
解题流程
- 1. 明确窗口/状态定义
- 2. 更新状态并维护约束
- 3. 用边界样例验证
常见失分点
- Confusing partitioning logic can lead to incorrect median calculations.
- Attempting simple binary search without handling rotation leads to incorrect indices.
- Using a single binary search and assuming the first match is the left boundary.
推荐题单梯度
寻找两个正序数组的中位数
Find the median of two sorted arrays using binary search for efficient O(log(min(m, n))) time complexity.
搜索旋转排序数组
Find the index of a target in a rotated sorted array using a careful binary search that handles pivot shifts.
在排序数组中查找元素的第一个和最后一个位置
Locate the first and last index of a target in a sorted array using binary search for precise O(log n) performance.
搜索插入位置
Find the correct index for a target value in a sorted array using binary search, or return the position where it should …
x 的平方根
Solve the Sqrt(x) problem using binary search to find the integer square root of a number without built-in operators.
搜索二维矩阵
Search a 2D matrix efficiently using binary search over its linearized index, ensuring correctness in row-major sorted a…
搜索旋转排序数组 II
Determine if a target exists in a rotated sorted array that may contain duplicates using a binary search variation effic…
寻找旋转排序数组中的最小值
Find the minimum element in a rotated sorted array using binary search to efficiently identify the point of rotation.
寻找旋转排序数组中的最小值 II
Find the minimum in a rotated sorted array with possible duplicates using binary search.
寻找峰值
Find Peak Element leverages binary search for efficiently locating a peak in an array, a problem commonly asked in techn…
两数之和 II - 输入有序数组
Solve the Two Sum II problem efficiently using binary search over a valid answer space in a sorted array.
长度最小的子数组
Find the minimal length of a subarray whose sum is greater than or equal to the target using efficient algorithms.
搜索二维矩阵 II
Efficiently search for a target in a 2D matrix using binary search and matrix properties.
H 指数 II
Compute a researcher's H-Index from a sorted citation array using binary search over the valid answer space efficiently.
第一个错误的版本
Find the first bad version of a product using binary search, minimizing the number of API calls.
寻找重复数
The problem involves finding the duplicate number in an array of integers, using a binary search approach over the valid…
计算右侧小于当前元素的个数
Solve the Count of Smaller Numbers After Self problem using binary search and optimized algorithms.
区间和的个数
Count the number of subarray sums within a given inclusive range using optimized divide-and-conquer techniques efficient…
将数据流变为多个不相交区间
The problem involves designing a class to summarize a data stream of non-negative integers as disjoint intervals using b…
矩形区域不超过 K 的最大数值和
Solve the "Max Sum of Rectangle No Larger Than K" problem using binary search over the valid sum space to optimize space…
有效的完全平方数
Determine if a given positive integer is a perfect square using a binary search approach over potential square roots eff…
猜数字大小
Find the picked number efficiently using binary search while adjusting guesses based on higher or lower feedback in this…
有序矩阵中第 K 小的元素
Find the kth smallest element in a sorted n x n matrix using efficient binary search or heap strategies for optimized me…
第 N 位数字
Given n, efficiently find the nth digit in the infinite integer sequence using a binary search over valid positions.
排列硬币
Determine the maximum number of complete staircase rows possible with n coins using a binary search approach.
132 模式
Identify whether a given integer array contains a 132 pattern subsequence using efficient stack and search techniques.
供暖器
Determine the minimum heater radius to cover all houses using a binary search over potential radius values efficiently.
最小好进制
Find the smallest good base of an integer n using binary search over the valid answer space.
翻转对
Count the number of reverse pairs in a given integer array using efficient algorithms like binary search and merge sort.
非重叠矩形中的随机点
Design an algorithm to pick random points within non-overlapping rectangles using binary search and reservoir sampling.
按权重随机选择
Random Pick with Weight requires implementing a probabilistic index picker using prefix sums and binary search efficient…
有序数组中的单一元素
Find the single non-duplicate element in a sorted array where every other element appears exactly twice.
有效三角形的个数
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.
找到 K 个最接近的元素
Identify the k integers closest to a target x in a sorted array using binary search and two-pointer strategies efficient…
乘法表中第k小的数
Find the kth smallest number in an m x n multiplication table using binary search over the valid answer space.
二分查找
Solve the Binary Search problem by finding the index of a target value in a sorted array with O(log n) complexity.
乘积小于 K 的子数组
Count subarrays with a product strictly less than a given value k using efficient algorithms like binary search and slid…
找出第 K 小的数对距离
Solve Find K-th Smallest Pair Distance by sorting nums, then binary searching the distance and counting valid pairs with…
我的日程安排表 I
Implement a calendar supporting non-overlapping event bookings using binary search for efficient insertion and conflict …
我的日程安排表 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…
寻找比目标字母大的最小字母
Locate the smallest character in a sorted array that is strictly greater than a given target using efficient binary sear…
到达终点数字
Determine the minimum number of moves to reach a target on an infinite number line using step increments, leveraging bin…
水位上升的泳池中游泳
Solve the problem of swimming through a grid of rising water with a binary search on the valid answer space.
第 K 个最小的质数分数
Find the k-th smallest fraction from a sorted array of unique primes using a binary search over the answer space.
阶乘函数后 K 个零
Solve for the number of integers whose factorial ends with a specific number of zeroes using binary search 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…
山脉数组的峰顶索引
Find the peak index in a mountain array using binary search for efficient O(log n) time complexity.
和至少为 K 的最短子数组
Find the shortest subarray with a sum of at least k using binary search and sliding window techniques.
爱吃香蕉的珂珂
Koko Eating Bananas challenges you to find the minimum eating speed to finish piles of bananas in a given time using bin…
第 N 个神奇数字
Find the nth magical number divisible by a or b, using binary search to efficiently handle large inputs.
基于时间的键值存储
Implement a time-based key-value store that retrieves the latest value at a given timestamp using efficient binary searc…
最大连续1的个数 III
Find the longest consecutive ones in a binary array by optimally flipping at most k zeros using sliding window technique…
在 D 天内送达包裹的能力
Find the minimum ship capacity needed to ship all packages within D days, ensuring the cargo is shipped in the given ord…
最长重复子串
Find the longest duplicated substring in a string using binary search, sliding window, and rolling hash techniques.
山脉数组中查找目标值
Find in Mountain Array requires locating a target using binary search over a peak-structured array efficiently in intera…
子数组中占绝大多数的元素
Efficiently find the majority element in any subarray using a data structure optimized for multiple range queries.
丑数 III
Find the nth positive integer divisible by a, b, or c using binary search over the answer space efficiently and accurate…
尽可能使字符串相等
Optimize substring transformations using a binary search approach to maximize the change within a budget.
找出给定方程的正整数解
Determine all positive integer pairs that satisfy a hidden monotonic function for a given target using binary search ove…
搜索推荐系统
Design a search suggestion system that provides the top three lexicographically smallest products matching a search word…
使结果不超过阈值的最小除数
Find the smallest divisor such that the sum of all divided array elements is less than or equal to the threshold.
元素和小于等于阈值的正方形的最大边长
This problem challenges you to find the largest square in a matrix with a sum below a given threshold using binary searc…
转变数组后最接近目标值的数组和
Find the integer that mutates all larger elements in an array to minimize the sum difference to a target efficiently.
矩阵中战斗力最弱的 K 行
Find the k weakest rows in a binary matrix where rows contain soldiers and civilians, using sorting and binary search te…
推文计数
Design an efficient solution to track and retrieve tweet counts over different frequencies using binary search and hash …
统计有序矩阵中的负数
Count Negative Numbers in a Sorted Matrix requires counting negative numbers in a matrix sorted in non-increasing order …
两个数组间的距离值
Calculate the distance value between two integer arrays by determining how many elements in arr1 don't have a close coun…
有序矩阵中的第 k 个最小数组和
Find the kth smallest sum in a matrix with sorted rows using binary search and a heap-based approach.
制作 m 束花所需的最少天数
Determine the minimum number of days required to make m bouquets using k adjacent flowers efficiently with binary search…
满足条件的子序列数目
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…
找到最接近目标值的函数值
In this problem, you'll use binary search to find the closest value of a mysterious function to a given target.
第 k 个缺失的正整数
Find the kth missing positive integer in a strictly increasing array using binary search over the answer space efficient…
两球之间的磁力
Maximize the minimum magnetic force between balls by strategically placing them in baskets using binary search on positi…
删除最短的子数组使剩余数组有序
Find the shortest subarray to remove in order to make an array non-decreasing using binary search and two-pointer techni…
特殊数组的特征值
Determine if an array has exactly x elements greater than or equal to x using binary search over the answer space.
最小体力消耗路径
Find the minimum effort required to travel from the top-left to the bottom-right of a grid, considering height differenc…
销售价值减少的颜色球
Maximize total value by greedily selling diminishing-valued colored balls based on inventory and customer orders.
通过指令创建有序数组
The problem asks to compute the cost of inserting elements into a sorted array using a series of instructions.
将数组分成三个子数组的方案数
The problem requires finding the number of ways to split an array into three subarrays where each split meets a certain …
放置盒子
Optimize the number of boxes touching the floor in a cubic room using binary search to minimize floor occupancy.
袋子里最少数目的球
Find the minimum penalty (maximum balls in a bag) after performing up to maxOperations to split bags of balls.
好子数组的最大分数
Maximize the score of a good subarray using binary search to explore the valid answer space with a focus on two-pointer …
有界数组中指定下标处的最大值
Maximize the value at a given index of an array with constraints using binary search over the valid answer space.
绝对差值和
Minimize the absolute sum difference between two integer arrays by replacing at most one element from the first array.
最高频元素的频数
Maximize the frequency of an element in an array by incrementing at most `k` elements. Use binary search and greedy tech…
最近的房间
Find the closest hotel room meeting minimum size requirements using binary search over the valid answer space efficientl…
包含每个查询的最小区间
Find the smallest interval containing each query efficiently using binary search.
下标对中的最大距离
Find the maximum distance between a pair of values in two non-increasing integer arrays using binary search.
向下取整数对和
The problem asks to calculate the sum of floor divisions for all pairs in a given integer array, using an efficient meth…
准时到达的列车最小时速
This problem asks to find the minimum speed of trains to reach on time using binary search.
装包裹的最小浪费空间
Minimize the wasted space when packaging items into boxes, considering package and box size constraints.
找到需要补充粉笔的学生编号
Identify the first student who will run out of chalk using a simulation with prefix sums and binary search.
可移除字符的最大数目
Use binary search and a subsequence check to find the largest removable prefix that still keeps p inside s.
寻找峰值 II
Locate any peak in a 2D matrix using binary search across rows or columns for efficient discovery and verification.
最长公共子路径
The Longest Common Subpath problem requires finding the longest subpath shared by all paths in a graph using binary sear…
收集足够苹果的最小花园周长
Find the minimum perimeter of a square garden that holds enough apples based on a specific formula involving binary sear…
找出到每个位置为止最长的有效障碍赛跑路线
Compute the longest valid obstacle course at each position using binary search and careful array tracking techniques eff…
你能穿过矩阵的最后一天
Find the last day to walk from top to bottom in a flooded matrix by using binary search and graph traversal techniques.
考试的最大困扰度
Maximize the Confusion of an Exam requires adjusting at most k answers to create the longest consecutive true or false s…
两个有序数组的第 K 小乘积
Find the kth smallest product from two sorted arrays using binary search across possible product values efficiently.
蜡烛之间的盘子
Determine the number of plates between candles in a given substring using binary search and prefix sum techniques.
分配给商店的最多商品的最小值
Distribute products to stores so the largest store allocation is minimized using binary search over possible maximums.
每一个查询的最大美丽值
Determine the maximum beauty of items affordable for each query using efficient binary search and sorting techniques.
你可以安排的最多任务数目
Maximize the number of tasks that can be completed by efficiently using workers and magical pills.
找出数组排序后的目标下标
Find the target indices of a sorted array and return them in increasing order using binary search and sorting techniques…
摘水果
Compute the maximum fruits collectable on an infinite line by moving at most k steps from a start position efficiently.
使数组 K 递增的最少操作次数
This problem requires finding the minimum number of operations to make an array K-increasing using binary search over th…
同时运行 N 台电脑的最长时间
Solve the problem of determining the maximum running time of n computers using a set of batteries.
统计数组中好三元组数目
Count Good Triplets in an Array requires tracking index orders across two permutations efficiently using binary search.
完成旅途的最少时间
Find the minimum time required for buses to complete at least totalTrips using binary search over time multiples.
构造字符串的总得分和
Calculate the sum of scores of built strings by analyzing longest common prefixes with suffixes in a string using effici…
每个小孩最多能分到多少糖果
Maximize candies allocation for k children by dividing piles into sub-piles using binary search.
花园的最大总美丽值
Determine the maximum total beauty of gardens by strategically planting flowers using binary search over achievable flow…
逃离火灾
Maximize the time you can stay at your starting position before moving to safely reach the safehouse while avoiding fire…
毯子覆盖的最多白色砖块数
Solve Maximum White Tiles Covered by a Carpet by sorting intervals, checking optimal carpet starts, and counting full pl…
以组为单位订音乐会的门票
Design a ticketing system to allocate concert seats in specific groupings while efficiently handling seat reservations.
咒语和药水的成功对数
Count how many potions pair successfully with each spell using binary search over sorted potion strengths efficiently.
统计得分小于 K 的子数组数目
Count all non-empty subarrays whose score, defined as sum times length, is strictly less than a given integer k efficien…
坐上公交的最晚时间
Find the latest time to catch a bus based on departure times, passenger arrivals, and capacity using binary search over …
最小差值平方和
Calculate the minimum sum of squared differences between two arrays using limited modifications and binary search techni…
分组的最大数量
Determine the maximum number of ordered non-empty student groups for a competition using grades array analysis and binar…
和有限的最长子序列
Find the maximum size of a subsequence from nums with a sum less than or equal to each query value.
预算内的最多机器人数目
Determine the maximum number of consecutive robots you can operate without exceeding a given budget using efficient bina…
按位或最大的最小子数组长度
Find the smallest subarrays with the maximum bitwise OR for each starting index in an array.
最长上传前缀
Calculate the longest continuous uploaded prefix in a video stream efficiently using a mix of binary search and data str…
满足不等式的数对数目
Count pairs in two arrays satisfying a given inequality condition using binary search over the valid answer space.
使数组相等的最小开销
Find the minimum cost to make all elements of an array equal by using binary search over valid answers.
下一个更大元素 IV
Find the second greater integer for each element in an array using binary search and monotonic stack techniques.
根据限制分割消息
Split Message Based on Limit requires dividing a string into parts with length constraints using a calculated suffix pat…
青蛙过河 II
Frog Jump II requires finding the minimal maximum jump length for a frog to traverse stones forward and backward efficie…
最小化两个数组中的最大值
Minimize the Maximum of Two Arrays requires finding the smallest possible maximum number across two arrays, using binary…
礼盒的最大甜蜜度
Maximize the tastiness of a candy basket by choosing k candies from a list of candy prices.
最大化城市的最小电量
Determine the maximum minimum power a city can achieve by strategically adding power stations using binary search and pr…
正整数和负整数的最大计数
Compute the maximum count between positive and negative integers in a sorted array using efficient binary search countin…
两个线段获得的最多奖品
Maximize the total prizes by choosing two segments of length k on a sorted line of prize positions efficiently using bin…
统计公平数对的数目
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.
求出最多标记下标
Maximize marked indices in an array by performing allowed operations, applying binary search to find the optimal count e…
完成所有任务的最少时间
Determine the minimum active time for a computer to complete all scheduled tasks within their specific time windows effi…
修车的最少时间
Find the minimum time to repair all cars using mechanics with different ranks, applying binary search over possible time…
质数减法运算
Determine if it's possible to make the array strictly increasing using prime subtractions.
使数组元素全部相等的最少操作次数
Find the minimum number of operations to make all elements in an array equal for each query.
将数组清空
Solve the "Make Array Empty" problem using binary search to determine the minimum number of operations required.
最大和查询
Find the maximum sum of paired elements from two arrays under query constraints using efficient binary search techniques…
数组的最大美丽值
Find the maximum beauty of an array by adjusting elements within a range using binary search and sliding window techniqu…
长度递增组的最大数目
Maximize the number of groups that can be formed with given usage limits, leveraging binary search for optimal solutions…
找出最安全路径
Find the Safest Path in a Grid uses binary search and BFS to maximize path safeness from thieves in a grid.
限制条件下元素之间的最小绝对差
Find the minimum absolute difference between two array elements that are at least x indices apart using binary search.
统计和小于目标的下标对数目
This problem asks you to count all index pairs in an array whose sum is strictly less than a given target value efficien…
最大合金数
Determine the maximum number of alloys possible using limited metal stock and budget, leveraging binary search efficient…
找到 Alice 和 Bob 可以相遇的建筑
Determine the leftmost building where Alice and Bob can meet using a binary search over valid move sequences.
使数组成为等数数组的最小代价
Determine the minimum cost to convert an integer array into a palindromic array using allowed element modifications effi…
执行操作使频率分数最大
Maximize the frequency score by applying up to k operations on a sorted array using binary search over valid answer spac…
统计移除递增子数组的数目 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
Find the longest special substring in a string that appears at least three times, or return -1 if no such substring exis…
找出出现至少三次的最长特殊子字符串 II
Find the longest special substring that occurs at least three times in a given string using binary search and hash table…
找出数组中的美丽下标 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.
标记所有下标的最早秒数 I
The problem asks to determine the earliest second to mark all indices in an array using a set of operations.
标记所有下标的最早秒数 II
This problem asks to determine the earliest second at which all indices in an array can be marked using a sequence of op…
边界元素是最大值的子数组数目
Count the subarrays where the first and last elements are the largest in the subarray, utilizing binary search over vali…
单面值组合的第 K 小金额
Find the kth smallest amount using only one coin denomination at a time, applying binary search efficiently over possibl…
大数组元素的乘积
Solve queries on a massive array of powers of two using binary search to efficiently compute modular products of subarra…
特殊数组 II
Determine whether each subarray meets the special condition of alternating parity for all adjacent elements efficiently …
物块放置查询
Determine if blocks can be placed on an infinite number line using queries, leveraging binary search over the valid answ…
找到按位或最接近 K 的子数组
Find a subarray with bitwise OR closest to a given value k with minimal absolute difference.
子数组按位与值为 K 的数目
The problem asks to find the number of subarrays with a given AND value in an array, utilizing binary search for optimiz…
统计满足 K 约束的子字符串数量 II
Count Substrings That Satisfy K-Constraint II requires finding valid substrings in a binary string based on a k-constrai…
范围内整数的最大得分
Maximize Score of Numbers in Ranges asks to find the maximum score by selecting integers within given intervals with a f…
最长上升路径的长度
Determine the maximum length of an increasing path in a 2D array using binary search over potential path lengths efficie…
移山所需的最少秒数
Determine the minimum seconds required to reduce a mountain to zero height using simultaneous workers efficiently.
执行操作后元素的最高频率 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…
检测相邻递增子数组 II
Find the largest k where two adjacent strictly increasing subarrays of length k exist using binary search techniques.
零数组变换 II
Zero Array Transformation II requires determining the minimum query sequence to convert all array elements to zero using…
最小化相邻元素的最大差值
Minimize the maximum adjacent element difference by filling missing values with two chosen numbers.
字符相同的最短子字符串 I
Minimize the length of the longest substring with identical characters after at most numOps changes in a binary string.
字符相同的最短子字符串 II
Find the minimal length of a substring with identical characters using binary search and controlled character flips effi…
收集连续 K 个袋子可以获得的最多硬币数量
Solve the problem of maximizing coins from selecting k consecutive bags, using binary search and sliding window techniqu…
最大化游戏分数的最小值
Maximizing the minimum score after at most m moves, leveraging binary search and greedy strategies over an array of scor…
分割正方形 I
Find the minimum y-coordinate of a horizontal line that balances the areas of squares above and below it.
分割正方形 II
Separate Squares II requires finding the minimum y-coordinate such that squares' areas are split evenly above and below …
最短匹配子字符串
Find the shortest substring in a string that matches a pattern with exactly two wildcards efficiently using binary searc…
正方形上的点之间的最大距离
Select k points on a square boundary to maximize minimum Manhattan distance using binary search and greedy placement str…
水果成篮 II
Determine the number of fruit types that remain unplaced after all allocations in the "Fruits Into Baskets II" problem.
水果成篮 III
Fruits Into Baskets III requires placing fruits into baskets efficiently using binary search over the answer space for c…
操作后最大活跃区段数 II
Maximize the number of active sections in a binary string with at most one trade.
针对图的路径存在性查询 II
Solve path existence queries in a graph using binary search on the answer space, focusing on sorted nodes and maximum di…
升级后最大生成树稳定性
Maximizing the stability of a spanning tree with upgrades requires careful optimization of edge strengths using binary s…
数组的最小稳定性因子
The problem requires finding the minimum stability factor of an array by utilizing binary search and math-based optimiza…
包含 K 个连通分量需要的最小时间
Find the minimum time to remove edges such that a graph with n nodes has at least k connected components.
最小化连通分量的最大成本
Minimize Maximum Component Cost leverages binary search over edge weights to optimize the cost of graph components after…