识别信号
- The candidate demonstrates a good understanding of greedy algorithms by proposing a solution based on the greedy choice paradigm.
- The candidate explains invariant validation correctly, ensuring that they track gas levels and station indices effectively throughout the solution.
- Look for a clear understanding of greedy algorithms and how to implement the left-to-right and right-to-left passes.
解题流程
- 1. 明确窗口/状态定义
- 2. 更新状态并维护约束
- 3. 用边界样例验证
常见失分点
- Failing to consider the case where the total gas is less than the total cost, which leads to an incorrect answer.
- Failing to correctly handle the right-to-left pass, potentially leading to incorrect candy assignments.
- Overlooking the need for a custom sorting function for concatenation comparisons.
推荐题单梯度
加油站
The Gas Station problem requires finding the starting station index for a full circular trip with gas stations and costs…
分发糖果
The Candy problem is a greedy algorithm challenge where you need to minimize candy distribution while satisfying certain…
最大数
The problem asks to arrange integers to form the largest possible number, focusing on greedy algorithms and string handl…
摆动排序 II
Rearrange an array in a way that every odd-indexed element is greater than its adjacent even-indexed elements.
按要求补齐数组
Patching Array requires adding the minimum numbers to cover all sums from 1 to n using greedy choices and invariant chec…
递增的三元子序列
Identify if an array contains a strictly increasing triplet by maintaining a running minimal and middle value efficientl…
最长回文串
Determine the length of the longest palindrome constructible from a given string using greedy counting and frequency tra…
强密码检验器
The Strong Password Checker problem challenges you to optimize password strength while minimizing steps using greedy alg…
用最少数量的箭引爆气球
Find the minimum number of arrows needed to burst all balloons by considering greedy choice and invariant validation.
IPO
Maximize total capital by selecting up to k projects, based on initial capital and project profits using a greedy strate…
超级洗衣机
Calculate the minimum moves to balance dresses across washing machines using a greedy strategy and invariant validation …
数组拆分
Maximize the sum of minimums of n pairs in a 2n integer array using a greedy pairing strategy efficiently.
种花问题
Determine if n new flowers can be planted in a flowerbed, ensuring no adjacent flowers using a greedy approach.
数组列表中的最大距离
Maximum Distance in Arrays uses a greedy running minimum and maximum from previous arrays to validate cross array distan…
课程表 III
Solve the 'Course Schedule III' problem with a greedy approach involving course selection and validation of constraints.
最大交换
Given an integer, swap at most two digits once to produce the largest possible number using greedy digit selection.
单调递增的数字
Determine the largest number less than or equal to n with digits in non-decreasing order using a greedy, invariant-drive…
设置交集大小至少为2
Solve the Set Intersection Size At Least Two problem using a greedy approach and invariant validation.
重构字符串
Reorganize a string so that no two adjacent characters are the same, if possible, using a greedy approach.
保持城市天际线
Maximize building heights in a city grid without changing the skyline, using greedy selection constrained by row and col…
雇佣 K 名工人的最低成本
Find the minimum cost to hire exactly k workers based on quality and wage expectations in this challenging greedy proble…
柠檬水找零
Determine if you can provide exact change to every customer at a lemonade stand using greedy bill management techniques.
翻转矩阵后的得分
Maximize the score of a binary matrix by flipping rows and columns using a greedy approach and validation of invariants.
最小差值 II
Determine the minimum possible difference between the largest and smallest numbers after adjusting each by plus or minus…
使数组唯一的最小增量
This problem challenges you to find the minimum moves to make all elements in an array unique by incrementing elements.
删列造序 II
Solve the "Delete Columns to Make Sorted II" problem by applying greedy choices and invariant validation to string array…
三角形的最大周长
Given an integer array, find the largest perimeter of a triangle formed from three of these lengths.
不含 AAA 或 BBB 的字符串
Solve the problem of constructing a string without consecutive 'AAA' or 'BBB' by applying a greedy approach with invaria…
坏了的计算器
Compute the minimum operations to transform startValue into target using doubling and decrementing, leveraging a greedy …
K 次取反后最大化的数组和
Maximize the sum of an integer array after exactly k negations using a greedy approach and invariant tracking for optima…
行相等的最少多米诺旋转
Minimize domino rotations to make either row identical in the problem of Minimum Domino Rotations For Equal Row.
将数组分成和相等的三个部分
Determine if an array can be partitioned into three non-empty parts with equal sum using greedy choice and validation.
两地调度
Two City Scheduling requires selecting optimal city assignments for 2n people to minimize total travel costs efficiently…
交换一次的先前排列
Find the lexicographically largest permutation smaller than the given array using exactly one swap, leveraging a greedy …
递减元素使数组呈锯齿状
Transform any integer array into a zigzag pattern with minimal decrements using a targeted greedy approach and invariant…
玩筹码
Compute the minimum cost to move all chips to one position using parity-based greedy moves efficiently.
分割平衡字符串
Split a string into the maximum number of balanced substrings where each substring has an equal number of 'L' and 'R'.
交换字符使得字符串相同
This problem requires determining the minimum number of swaps to make two strings equal by swapping characters between t…
重构 2 行二进制矩阵
Reconstruct a 2-row binary matrix by distributing column sums while respecting upper and lower row limits using greedy p…
6 和 9 组成的最大数字
Maximize a number by flipping at most one digit from 6 to 9 or vice versa.
破坏回文串
Given a palindrome, change exactly one character to make it non-palindromic and lexicographically smallest using a greed…
翻转子数组得到最大的数组值
Maximize the value of an array by reversing a subarray, focusing on greedy choices and invariant validation.
最多可以参加的会议数目
Maximize the number of events you can attend given their start and end days using a greedy strategy.
最大的团队表现值
Maximize the performance of a team by selecting up to k engineers with the highest performance based on speed and effici…
构造 K 个回文字符串
Determine if a string's characters can be rearranged to form exactly k non-empty palindrome strings using greedy validat…
非递增顺序的最小子序列
Find the minimum subsequence in non-increasing order such that its sum exceeds the sum of non-included elements.
最长快乐字符串
Solve the "Longest Happy String" problem using a greedy approach with validation of invariants for constructing the long…
和为 K 的最少斐波那契数字数目
Find the minimum number of Fibonacci numbers that sum up to a given integer k, using a greedy approach.
改变一个整数能得到的最大差值
Compute the maximum difference from changing digits in an integer using greedy choices and invariant checks efficiently.
检查一个字符串是否可以打破另一个字符串
This problem checks whether one string can break another using permutations and a greedy approach for comparison.
切割后面积最大的蛋糕
Maximize the area of a piece of cake after specified horizontal and vertical cuts using greedy algorithms and sorting.
最多 K 次交换相邻数位后得到的最小整数
Reorder digits using at most k adjacent swaps to produce the smallest possible integer, leveraging greedy selection effi…
三次操作后最大值与最小值的最小差
Find the minimum difference between the largest and smallest values in an array after performing at most three moves.
最多的不重叠子字符串
Find the maximum number of non-overlapping substrings in a given string, ensuring no two substrings intersect unless one…
最少的后缀翻转次数
Find the minimum number of operations to convert a binary string to a target string using bit flips.
排布二进制网格的最少交换次数
Compute the minimum number of adjacent row swaps to transform a binary grid so all upper-triangle cells are zero using a…
得到目标数组的最少函数调用次数
Calculate the minimum number of modify calls needed to convert an all-zero array into a given target array using greedy …
你可以获得的最大硬币数目
Solve the Maximum Number of Coins You Can Get using greedy pile selection and invariant validation to maximize your coin…
检查字符串是否可以通过排序子字符串得到另一个字符串
This problem requires checking if string 's' can be transformed into string 't' using substring sort operations.
所有排列中的最大和
Maximize the total sum of requests on nums by greedily assigning larger numbers to most frequently requested indices.
给定行和列的和求可行矩阵
Given row and column sums, find any valid matrix of non-negative integers that satisfies them.
找到处理最多请求的服务器
Given k servers and a series of requests, find the busiest server(s) using greedy strategies and efficient server tracki…
可以到达的最远建筑
Furthest Building You Can Reach explores a greedy approach with heap-based optimization to find the maximum reachable bu…
字符频次唯一的最小删除次数
Determine the minimum deletions needed to ensure all character frequencies in a string are unique using a greedy approac…
具有给定数值的最小字符串
Find the lexicographically smallest string of length n with a given numeric value k using a greedy approach.
完成所有任务的最少初始能量
Determine the minimum initial energy needed to finish all tasks using a greedy ordering based on required versus actual …
数组的最小偏移量
Given a positive integer array, repeatedly double or halve elements to minimize the difference between its largest and s…
石子游戏 VI
Determine the winner in Stone Game VI using a greedy strategy that accounts for each stone's dual value impact on Alice …
十-二进制数的最少数目
This problem asks to find the minimum number of deci-binary numbers needed to sum to a given number represented as a str…
修改后的最大二进制字符串
The problem asks to maximize a binary string using specific operations to get the highest possible value.
吃苹果的最大数目
Maximize apples eaten by choosing the best apples first, considering their rot days and available days to eat them.
卡车上的最大单元数
Maximize total units loaded on a truck by choosing boxes greedily based on highest units per box within truck capacity l…
重新排列后的最大子矩阵
Rearrange columns of a binary matrix to find the largest submatrix of 1s.
替换隐藏数字得到的最晚时间
Determine the latest valid time by replacing hidden digits using a greedy choice and invariant validation strategy effic…
移除石子的最大得分
Maximize the score in a solitaire game by optimally removing stones from three piles with a greedy approach.
构成特定和需要添加的最少元素
Compute the gap between current sum and goal, then greedily cover it with limit-sized additions to get the minimum count…
最大平均通过率
Maximize the average pass ratio by assigning extra guaranteed-passing students using a greedy heap strategy for optimal …
你能构造出连续值的最大数目
Find the maximum number of consecutive integer values starting from zero that can be formed using your coins array.
最少操作使数组递增
Calculate the minimum number of increments required to transform a given integer array into a strictly increasing sequen…
雪糕的最大数量
Maximize the number of ice cream bars a boy can buy by applying a greedy choice strategy based on cost sorting.
减小和重新排列数组后的最大元素
Determine the maximum value in an array after decreasing elements and rearranging using a greedy invariant approach.
构成交替字符串需要的最小交换次数
This problem requires finding the minimum number of swaps to make a binary string alternating or determine if it's impos…
插入后的最大值
Solve Maximum Value after Insertion by greedily placing x at the first digit that makes the resulting signed number larg…
合并若干三元组以形成目标三元组
Determine if target triplet can be formed by merging given triplets using greedy selection and invariant checks.
字符串中的最大奇数
Find the largest odd number in a string using a greedy approach with careful digit inspection and invariant checks.
消灭怪物的最大数量
Eliminate monsters by strategically using a weapon in a video game to stop them before they reach your city.
求和游戏
Determine if Alice can force a win in the Sum Game by strategically replacing '?' using a greedy and invariant approach.
新增的最少台阶数
Determine the fewest rungs to add to climb a strictly increasing ladder using a greedy step-by-step approach.
子字符串突变后可能得到的最大整数
Find the largest integer by mutating a substring of a number using a mapping array for each digit.
你可以工作的最大周数
Maximize the number of weeks you can work on projects with milestone constraints using a greedy approach and invariant v…
移除石子使总数最小
Minimize the total stones by repeatedly removing half from the largest pile using a greedy heap strategy.
构造元素不等于两相邻元素平均值的数组
Rearrange an array such that no element equals the average of its neighbors using a greedy approach.
数组元素的最小非零乘积
The problem asks to minimize the product of an array after performing bit-swapping operations on its binary representati…
使用特殊打字机键入单词的最少时间
Compute the minimum typing time by greedily taking the shorter circular move between consecutive letters, then adding on…
最大方阵和
Maximize the sum of an n x n integer matrix using row and column negation operations efficiently with a greedy approach.
转换字符串的最少操作次数
Minimize moves to convert a string of 'X' and 'O' to all 'O' by converting three consecutive characters to 'O'.
石子游戏 IX
In the Stone Game IX problem, Alice and Bob take turns removing stones, and Alice wins if the sum of removed stones is d…
使每位学生都有座位的最少移动次数
Calculate the minimum total moves to seat each student using greedy assignment and invariant validation efficiently.
如果相邻两个颜色均相同则删除当前颜色
Alice and Bob play a game removing colored pieces; Alice wins if she makes the last valid move.
两栋颜色不同且距离最远的房子
Maximize the distance between two houses with different colors by using a greedy approach and validating the choice.
网格图中机器人回家的最小代价
Find the minimum cost for a robot to return home in a grid with row and column movement costs.
从数组中移除最大值和最小值
The problem asks to remove the minimum and maximum elements from an array with the fewest deletions.
摧毁小行星
This problem requires destroying asteroids by choosing the right order of collisions based on mass, using a greedy appro…
用邮票贴满网格图
Determine if a binary grid can be fully covered using fixed-size stamps by applying a greedy placement and validation st…
全部开花的最早一天
Find the earliest day where all flower seeds are blooming based on their planting and growth times, using a greedy strat…
得到目标值的最少行动次数
Calculate the fewest steps to reach a target integer using increments and limited doubles with a greedy strategy.
打折购买糖果的最小开销
Minimize the total cost of buying candies using a greedy approach with a discount system based on candy prices.
拆分数位后四位数字的最小和
Find the minimum sum of two 2-digit numbers by splitting a four-digit number into two integers.
拿出最少数目的魔法豆
Determine the minimum beans to remove so all remaining non-empty bags have equal beans using a greedy approach.
构造限制重复的字符串
Construct a lexicographically largest string from a given string with no letter appearing more than a repeatLimit times …
向数组中追加 K 个整数
In this problem, you need to append k unique positive integers to a given array nums such that the sum is minimized.
K 次操作后最大化顶端元素
Maximize the topmost element in a pile after making exactly k moves using a greedy strategy and invariant checks.
字符串中最多数目的子序列
Maximize the number of subsequences by optimally adding a character to a given string to match a specified pattern.
将数组和减半的最少操作次数
Minimize operations to halve an array's sum using greedy choices and heap data structures.
转化时间需要的最少操作数
The problem asks to find the minimum number of operations to convert one time string to another using specific time incr…
K 次增加后的最大乘积
Maximize the product of an array after performing up to k increments using a greedy approach with heap optimization.
设计一个 ATM 机器
Design an ATM machine that stores and withdraws money with given denominations and prioritizes larger values during with…
移除指定数字得到的最大结果
Determine the largest possible number by removing one specific digit using a greedy approach and string iteration.
装满石头的背包的最大数量
Maximize the number of bags filled to capacity by distributing additional rocks using a greedy approach.
道路的最大总重要性
Assign unique values to cities to maximize the total importance of all roads using greedy selection based on city connec…
划分数组使最大差为 K
Find the minimum number of subsequences required such that the difference between the maximum and minimum value in each …
装满杯子需要的最短总时长
Determine the minimum seconds to fill cups of cold, warm, and hot water using a greedy selection strategy and invariant …
将数组排序的最少替换次数
Minimize the number of operations to make the array sorted in non-decreasing order by replacing elements with sums of tw…
赢得比赛需要的最少训练时长
Find the minimum hours of training needed to beat all opponents in a competition based on energy and experience.
最大回文数字
Form the largest palindromic number from a string of digits while maintaining a valid palindrome structure.
子字符串的最优划分
Given a string s, partition it into substrings with unique characters and return the minimum number of substrings.
完成所有交易的初始最少钱数
Find the minimum money required to complete all transactions in any order while considering cost and cashback.
最小异或
Minimize XOR problem asks for an integer that minimizes XOR with another, applying greedy choices for bit manipulation.
使数组相似的最少操作次数
Determine the minimum operations to make two arrays similar by adjusting pairs while respecting element frequencies and …
美丽整数的最小增量
Find the minimum addition to a number such that its digits sum to a value less than or equal to a given target.
图中最大星和
Find the maximum star sum in a graph with specific node values and edges, using greedy algorithms to select the optimal …
执行 K 次操作后的最大分数
Maximize your score by applying exactly k operations on an array using greedy selection and heap optimization techniques…
使数组中所有元素相等的最小操作数 II
Calculate the minimum operations to make two integer arrays equal using greedy adjustments with modular checks efficient…
最大子序列的分数
Maximize the score of a subsequence by selecting indices based on nums1 and nums2, using a greedy approach and sorting.
将珠子放入背包中
The "Put Marbles in Bags" problem challenges you to distribute marbles into bags for maximum score difference using gree…
替换一个数字后的最大差值
Find the largest difference by remapping a single digit in a number using a greedy approach to maximize and minimize out…
修改两个元素的最小分数
The problem asks for the minimum score after changing two elements of an array using a greedy approach.
最小和分割
Split a positive integer into two parts to minimize their sum using a greedy approach and sorting.
重排数组以得到最大前缀分数
Maximize the number of positive prefix sums by rearranging an integer array using a greedy, order-focused strategy.
将钱分给最多的儿童
Determine the maximum number of children who can each receive exactly 8 dollars using a greedy approach with validation …
K 件物品的最大和
Select k items from a bag containing 1, 0, and -1 to maximize sum using greedy choice and invariant validation strategie…
使子数组元素和相等
Solve Make K-Subarray Sums Equal by grouping circular indices with gcd cycles and minimizing each group to its median.
老鼠和奶酪
In 'Mice and Cheese', you must maximize the total reward of two mice eating cheese while respecting their preferences an…
K 个元素的最大和
Maximize your score by performing exactly k operations on an array using a greedy approach to select the highest values.
字典序最小的美丽字符串
Find the lexicographically smallest beautiful string larger than the given string using greedy choice and invariant vali…
最大或值
Maximize the bitwise OR of an array by applying at most k multiplication operations on selected elements.
购买两块巧克力
Determine the leftover money after buying exactly two chocolates using a greedy selection and sum validation approach.
执行子串操作后的字典序最小字符串
Given a string, perform operations to make it lexicographically smaller using a greedy approach with substring modificat…
合并后数组中的最大元素
This problem focuses on applying greedy choices and merging elements to find the largest element in an array.
包含三个字符串的最短字符串
Find the shortest string containing three given strings using a greedy approach while ensuring it is lexicographically s…
k-avoiding 数组的最小总和
Determine the minimum sum of a k-avoiding array by choosing distinct integers such that no pair sums to a given k.
找出美丽数组的最小和
Find the minimum possible sum of a beautiful array that satisfies the given conditions with the greedy approach.
使子序列的和等于目标的最少操作次数
The problem requires finding the minimum number of operations to form a subsequence summing to a target using powers of …
统计一个字符串的 k 子序列美丽值最大的数目
Determine the number of k-length unique subsequences in a string that maximize the sum of character frequencies efficien…
生成特殊数字的最少操作
Minimize operations to make a number divisible by 25 by deleting digits. Use greedy choice and invariant validation.
最大二进制奇数
Rearrange a binary string to form the largest odd binary number using a greedy approach and least significant bit valida…
将数组分割成最多数目的子数组
Maximize the number of subarrays in an array while ensuring each subarray's bitwise AND meets the minimum score requirem…
最小处理时间
Determine the minimum total processing time by optimally assigning tasks to multiple processors using a greedy approach.
数组的最小相等和
Find the minimum sum where two arrays become equal after replacing all zeros with positive integers using a greedy strat…
购买物品的最大开销
Maximize spending by carefully choosing the right items across multiple shops over m * n days.
最大异或乘积
Find the maximum value of (a XOR x) * (b XOR x) using greedy bitwise choices and invariant validation.
需要添加的硬币的最小数量
Determine the minimum number of coins to add so all values up to target are obtainable using a greedy sum approach.
划分数组并满足最大差限制
Divide an array into subarrays with a maximum element difference under a given threshold using a greedy approach.
找到最大周长的多边形
Determine the largest perimeter polygon from a set of side lengths using a greedy approach with invariant validation che…
通过操作使数组长度最小
Minimize the length of an integer array through a series of operations, using a greedy approach with modular arithmetic.
输入单词需要的最少按键次数 I
Calculate the minimum pushes to type a word using a remapped telephone keypad with greedy allocation of letters.
输入单词需要的最少按键次数 II
Given a word, find the minimum number of pushes to type it on a remapped keypad using a greedy approach.
给定操作次数内使剩余元素的或值最小
Minimize the bitwise OR of the remaining elements of an array after applying at most k operations.
重新分装苹果
Distribute packs of apples into boxes using a greedy strategy, minimizing the number of boxes selected efficiently and c…
幸福值最大化的选择方案
Maximize the happiness of selected children by choosing the k happiest ones and applying greedy strategies to minimize l…
替换字符串中的问号使分数最小
Minimize the cost of a string with '?' characters by replacing them with letters in lexicographical order while minimizi…
成为 K 特殊字符串需要删除的最少字符数
Minimize deletions to make a string k-special by adjusting character frequencies.
执行操作使数据元素之和大于等于 K
Given an array nums, find the minimum number of operations to make the sum of elements greater than or equal to k.
满足距离约束且字典序最小的字符串
Minimize a string lexicographically using a series of operations constrained by a given integer k.
使数组中位数等于 K 的最少操作数
The problem involves minimizing operations to make the median of an array equal to a given value k using a greedy approa…
覆盖所有点的最少矩形数目
Find the minimum number of rectangles needed to cover all points, given constraints on width and position.
使数组中所有元素相等的最小开销
Compute the minimum cost to make all elements equal using selective operations guided by greedy choices and invariant ch…
与敌人战斗后的最大分数
Solve the "Maximum Points After Enemy Battles" problem by maximizing points through greedy choices with energy validatio…
交换后字典序最小的字符串
Lexicographically Smallest String After a Swap involves finding the smallest string after swapping adjacent digits with …
切蛋糕的最小总开销 II
Solve Minimum Cost for Cutting Cake II by choosing optimal cuts using a greedy strategy while tracking cost increments p…
将 1 移动到末尾的最大操作次数
This problem requires finding the maximum number of operations to move ones to the end of a binary string.
新增道路查询后的最短距离 II
The problem involves calculating the shortest path from city 0 to city n-1 after each road addition, leveraging greedy c…
对 Bob 造成的最少伤害
Minimize the total damage dealt to Bob using power to eliminate enemies efficiently with greedy approach.
到达数组末尾的最大得分
Calculate the maximum score to reach the end of an array using greedy jumps based on array values and distances.
高度互不相同的最大塔高和
Assign heights to towers ensuring each height is unique and the total sum is maximized using greedy sorting techniques.
使数组非递减的最少除法操作次数
Determine the minimum number of division operations to make an array non-decreasing using a greedy and invariant-based s…
零数组变换 III
Zero Array Transformation III requires removing the minimum number of queries to make all elements zero using greedy val…
执行操作后不同元素的最大数量
Maximize distinct elements in an array by performing at most one operation on each element.
使每一列严格递增的最少操作次数
Calculate the minimum increments to make each column of a matrix strictly increasing using a greedy invariant approach.
将数组变相同的最小代价
Minimize cost to make arrays identical by performing operations with given constraints and a greedy strategy.
重新安排会议得到最多空余时间 II
Maximize free time by rescheduling at most one meeting using a greedy choice with invariant validation approach for arra…
吃披萨
Maximize the total weight gained by optimally eating pizzas in groups of four using greedy selection and invariant valid…
提取至多 K 个元素的最大总和
Find the maximum sum by selecting at most k elements from a 2D matrix respecting per-row limits using a greedy strategy.
字典序最小的生成字符串
Generate the lexicographically smallest string by merging str1 and str2 using a greedy approach with invariant checks.
不同字符数量最多为 K 时的最少删除数
You need to delete characters in a string to reduce its distinct characters to at most k.
数组元素相等转换
Transform Array to All Equal Elements requires careful greedy choices and validating invariants to achieve uniformity ef…
最小相邻交换至奇偶交替
Compute the minimum adjacent swaps to make array elements alternate between even and odd using greedy and invariant chec…
划分数组得到最大异或运算和与运算之和
Partition the array into three subsequences to maximize XOR and AND operations with a greedy approach.