题库chevron_right贪心·invariant

贪心·invariant 模式

198 道题目

模式页适合用来建立可复用解题框架。先识别题目特征,再按固定流程解释状态定义、转移和边界。

识别信号

  • 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. 1. 明确窗口/状态定义
  2. 2. 更新状态并维护约束
  3. 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.

推荐题单梯度

#题目难度
134

加油站

The Gas Station problem requires finding the starting station index for a full circular trip with gas stations and costs…

中等
135

分发糖果

The Candy problem is a greedy algorithm challenge where you need to minimize candy distribution while satisfying certain…

困难
179

最大数

The problem asks to arrange integers to form the largest possible number, focusing on greedy algorithms and string handl…

中等
324

摆动排序 II

Rearrange an array in a way that every odd-indexed element is greater than its adjacent even-indexed elements.

中等
330

按要求补齐数组

Patching Array requires adding the minimum numbers to cover all sums from 1 to n using greedy choices and invariant chec…

困难
334

递增的三元子序列

Identify if an array contains a strictly increasing triplet by maintaining a running minimal and middle value efficientl…

中等
409

最长回文串

Determine the length of the longest palindrome constructible from a given string using greedy counting and frequency tra…

简单
420

强密码检验器

The Strong Password Checker problem challenges you to optimize password strength while minimizing steps using greedy alg…

困难
452

用最少数量的箭引爆气球

Find the minimum number of arrows needed to burst all balloons by considering greedy choice and invariant validation.

中等
502

IPO

Maximize total capital by selecting up to k projects, based on initial capital and project profits using a greedy strate…

困难
517

超级洗衣机

Calculate the minimum moves to balance dresses across washing machines using a greedy strategy and invariant validation …

困难
561

数组拆分

Maximize the sum of minimums of n pairs in a 2n integer array using a greedy pairing strategy efficiently.

简单
605

种花问题

Determine if n new flowers can be planted in a flowerbed, ensuring no adjacent flowers using a greedy approach.

简单
624

数组列表中的最大距离

Maximum Distance in Arrays uses a greedy running minimum and maximum from previous arrays to validate cross array distan…

中等
630

课程表 III

Solve the 'Course Schedule III' problem with a greedy approach involving course selection and validation of constraints.

困难
670

最大交换

Given an integer, swap at most two digits once to produce the largest possible number using greedy digit selection.

中等
738

单调递增的数字

Determine the largest number less than or equal to n with digits in non-decreasing order using a greedy, invariant-drive…

中等
757

设置交集大小至少为2

Solve the Set Intersection Size At Least Two problem using a greedy approach and invariant validation.

困难
767

重构字符串

Reorganize a string so that no two adjacent characters are the same, if possible, using a greedy approach.

中等
807

保持城市天际线

Maximize building heights in a city grid without changing the skyline, using greedy selection constrained by row and col…

中等
857

雇佣 K 名工人的最低成本

Find the minimum cost to hire exactly k workers based on quality and wage expectations in this challenging greedy proble…

困难
860

柠檬水找零

Determine if you can provide exact change to every customer at a lemonade stand using greedy bill management techniques.

简单
861

翻转矩阵后的得分

Maximize the score of a binary matrix by flipping rows and columns using a greedy approach and validation of invariants.

中等
910

最小差值 II

Determine the minimum possible difference between the largest and smallest numbers after adjusting each by plus or minus…

中等
945

使数组唯一的最小增量

This problem challenges you to find the minimum moves to make all elements in an array unique by incrementing elements.

中等
955

删列造序 II

Solve the "Delete Columns to Make Sorted II" problem by applying greedy choices and invariant validation to string array…

中等
976

三角形的最大周长

Given an integer array, find the largest perimeter of a triangle formed from three of these lengths.

简单
984

不含 AAA 或 BBB 的字符串

Solve the problem of constructing a string without consecutive 'AAA' or 'BBB' by applying a greedy approach with invaria…

中等
991

坏了的计算器

Compute the minimum operations to transform startValue into target using doubling and decrementing, leveraging a greedy …

中等
1005

K 次取反后最大化的数组和

Maximize the sum of an integer array after exactly k negations using a greedy approach and invariant tracking for optima…

简单
1007

行相等的最少多米诺旋转

Minimize domino rotations to make either row identical in the problem of Minimum Domino Rotations For Equal Row.

中等
1013

将数组分成和相等的三个部分

Determine if an array can be partitioned into three non-empty parts with equal sum using greedy choice and validation.

简单
1029

两地调度

Two City Scheduling requires selecting optimal city assignments for 2n people to minimize total travel costs efficiently…

中等
1053

交换一次的先前排列

Find the lexicographically largest permutation smaller than the given array using exactly one swap, leveraging a greedy …

中等
1144

递减元素使数组呈锯齿状

Transform any integer array into a zigzag pattern with minimal decrements using a targeted greedy approach and invariant…

中等
1217

玩筹码

Compute the minimum cost to move all chips to one position using parity-based greedy moves efficiently.

简单
1221

分割平衡字符串

Split a string into the maximum number of balanced substrings where each substring has an equal number of 'L' and 'R'.

简单
1247

交换字符使得字符串相同

This problem requires determining the minimum number of swaps to make two strings equal by swapping characters between t…

中等
1253

重构 2 行二进制矩阵

Reconstruct a 2-row binary matrix by distributing column sums while respecting upper and lower row limits using greedy p…

中等
1323

6 和 9 组成的最大数字

Maximize a number by flipping at most one digit from 6 to 9 or vice versa.

简单
1328

破坏回文串

Given a palindrome, change exactly one character to make it non-palindromic and lexicographically smallest using a greed…

中等
1330

翻转子数组得到最大的数组值

Maximize the value of an array by reversing a subarray, focusing on greedy choices and invariant validation.

困难
1353

最多可以参加的会议数目

Maximize the number of events you can attend given their start and end days using a greedy strategy.

中等
1383

最大的团队表现值

Maximize the performance of a team by selecting up to k engineers with the highest performance based on speed and effici…

困难
1400

构造 K 个回文字符串

Determine if a string's characters can be rearranged to form exactly k non-empty palindrome strings using greedy validat…

中等
1403

非递增顺序的最小子序列

Find the minimum subsequence in non-increasing order such that its sum exceeds the sum of non-included elements.

简单
1405

最长快乐字符串

Solve the "Longest Happy String" problem using a greedy approach with validation of invariants for constructing the long…

中等
1414

和为 K 的最少斐波那契数字数目

Find the minimum number of Fibonacci numbers that sum up to a given integer k, using a greedy approach.

中等
1432

改变一个整数能得到的最大差值

Compute the maximum difference from changing digits in an integer using greedy choices and invariant checks efficiently.

中等
1433

检查一个字符串是否可以打破另一个字符串

This problem checks whether one string can break another using permutations and a greedy approach for comparison.

中等
1465

切割后面积最大的蛋糕

Maximize the area of a piece of cake after specified horizontal and vertical cuts using greedy algorithms and sorting.

中等
1505

最多 K 次交换相邻数位后得到的最小整数

Reorder digits using at most k adjacent swaps to produce the smallest possible integer, leveraging greedy selection effi…

困难
1509

三次操作后最大值与最小值的最小差

Find the minimum difference between the largest and smallest values in an array after performing at most three moves.

中等
1520

最多的不重叠子字符串

Find the maximum number of non-overlapping substrings in a given string, ensuring no two substrings intersect unless one…

困难
1529

最少的后缀翻转次数

Find the minimum number of operations to convert a binary string to a target string using bit flips.

中等
1536

排布二进制网格的最少交换次数

Compute the minimum number of adjacent row swaps to transform a binary grid so all upper-triangle cells are zero using a…

中等
1558

得到目标数组的最少函数调用次数

Calculate the minimum number of modify calls needed to convert an all-zero array into a given target array using greedy …

中等
1561

你可以获得的最大硬币数目

Solve the Maximum Number of Coins You Can Get using greedy pile selection and invariant validation to maximize your coin…

中等
1585

检查字符串是否可以通过排序子字符串得到另一个字符串

This problem requires checking if string 's' can be transformed into string 't' using substring sort operations.

困难
1589

所有排列中的最大和

Maximize the total sum of requests on nums by greedily assigning larger numbers to most frequently requested indices.

中等
1605

给定行和列的和求可行矩阵

Given row and column sums, find any valid matrix of non-negative integers that satisfies them.

中等
1606

找到处理最多请求的服务器

Given k servers and a series of requests, find the busiest server(s) using greedy strategies and efficient server tracki…

困难
1642

可以到达的最远建筑

Furthest Building You Can Reach explores a greedy approach with heap-based optimization to find the maximum reachable bu…

中等
1647

字符频次唯一的最小删除次数

Determine the minimum deletions needed to ensure all character frequencies in a string are unique using a greedy approac…

中等
1663

具有给定数值的最小字符串

Find the lexicographically smallest string of length n with a given numeric value k using a greedy approach.

中等
1665

完成所有任务的最少初始能量

Determine the minimum initial energy needed to finish all tasks using a greedy ordering based on required versus actual …

困难
1675

数组的最小偏移量

Given a positive integer array, repeatedly double or halve elements to minimize the difference between its largest and s…

困难
1686

石子游戏 VI

Determine the winner in Stone Game VI using a greedy strategy that accounts for each stone's dual value impact on Alice …

中等
1689

十-二进制数的最少数目

This problem asks to find the minimum number of deci-binary numbers needed to sum to a given number represented as a str…

中等
1702

修改后的最大二进制字符串

The problem asks to maximize a binary string using specific operations to get the highest possible value.

中等
1705

吃苹果的最大数目

Maximize apples eaten by choosing the best apples first, considering their rot days and available days to eat them.

中等
1710

卡车上的最大单元数

Maximize total units loaded on a truck by choosing boxes greedily based on highest units per box within truck capacity l…

简单
1727

重新排列后的最大子矩阵

Rearrange columns of a binary matrix to find the largest submatrix of 1s.

中等
1736

替换隐藏数字得到的最晚时间

Determine the latest valid time by replacing hidden digits using a greedy choice and invariant validation strategy effic…

简单
1753

移除石子的最大得分

Maximize the score in a solitaire game by optimally removing stones from three piles with a greedy approach.

中等
1785

构成特定和需要添加的最少元素

Compute the gap between current sum and goal, then greedily cover it with limit-sized additions to get the minimum count…

中等
1792

最大平均通过率

Maximize the average pass ratio by assigning extra guaranteed-passing students using a greedy heap strategy for optimal …

中等
1798

你能构造出连续值的最大数目

Find the maximum number of consecutive integer values starting from zero that can be formed using your coins array.

中等
1827

最少操作使数组递增

Calculate the minimum number of increments required to transform a given integer array into a strictly increasing sequen…

简单
1833

雪糕的最大数量

Maximize the number of ice cream bars a boy can buy by applying a greedy choice strategy based on cost sorting.

中等
1846

减小和重新排列数组后的最大元素

Determine the maximum value in an array after decreasing elements and rearranging using a greedy invariant approach.

中等
1864

构成交替字符串需要的最小交换次数

This problem requires finding the minimum number of swaps to make a binary string alternating or determine if it's impos…

中等
1881

插入后的最大值

Solve Maximum Value after Insertion by greedily placing x at the first digit that makes the resulting signed number larg…

中等
1899

合并若干三元组以形成目标三元组

Determine if target triplet can be formed by merging given triplets using greedy selection and invariant checks.

中等
1903

字符串中的最大奇数

Find the largest odd number in a string using a greedy approach with careful digit inspection and invariant checks.

简单
1921

消灭怪物的最大数量

Eliminate monsters by strategically using a weapon in a video game to stop them before they reach your city.

中等
1927

求和游戏

Determine if Alice can force a win in the Sum Game by strategically replacing '?' using a greedy and invariant approach.

中等
1936

新增的最少台阶数

Determine the fewest rungs to add to climb a strictly increasing ladder using a greedy step-by-step approach.

中等
1946

子字符串突变后可能得到的最大整数

Find the largest integer by mutating a substring of a number using a mapping array for each digit.

中等
1953

你可以工作的最大周数

Maximize the number of weeks you can work on projects with milestone constraints using a greedy approach and invariant v…

中等
1962

移除石子使总数最小

Minimize the total stones by repeatedly removing half from the largest pile using a greedy heap strategy.

中等
1968

构造元素不等于两相邻元素平均值的数组

Rearrange an array such that no element equals the average of its neighbors using a greedy approach.

中等
1969

数组元素的最小非零乘积

The problem asks to minimize the product of an array after performing bit-swapping operations on its binary representati…

中等
1974

使用特殊打字机键入单词的最少时间

Compute the minimum typing time by greedily taking the shorter circular move between consecutive letters, then adding on…

简单
1975

最大方阵和

Maximize the sum of an n x n integer matrix using row and column negation operations efficiently with a greedy approach.

中等
2027

转换字符串的最少操作次数

Minimize moves to convert a string of 'X' and 'O' to all 'O' by converting three consecutive characters to 'O'.

简单
2029

石子游戏 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…

中等
2037

使每位学生都有座位的最少移动次数

Calculate the minimum total moves to seat each student using greedy assignment and invariant validation efficiently.

简单
2038

如果相邻两个颜色均相同则删除当前颜色

Alice and Bob play a game removing colored pieces; Alice wins if she makes the last valid move.

中等
2078

两栋颜色不同且距离最远的房子

Maximize the distance between two houses with different colors by using a greedy approach and validating the choice.

简单
2087

网格图中机器人回家的最小代价

Find the minimum cost for a robot to return home in a grid with row and column movement costs.

中等
2091

从数组中移除最大值和最小值

The problem asks to remove the minimum and maximum elements from an array with the fewest deletions.

中等
2126

摧毁小行星

This problem requires destroying asteroids by choosing the right order of collisions based on mass, using a greedy appro…

中等
2132

用邮票贴满网格图

Determine if a binary grid can be fully covered using fixed-size stamps by applying a greedy placement and validation st…

困难
2136

全部开花的最早一天

Find the earliest day where all flower seeds are blooming based on their planting and growth times, using a greedy strat…

困难
2139

得到目标值的最少行动次数

Calculate the fewest steps to reach a target integer using increments and limited doubles with a greedy strategy.

中等
2144

打折购买糖果的最小开销

Minimize the total cost of buying candies using a greedy approach with a discount system based on candy prices.

简单
2160

拆分数位后四位数字的最小和

Find the minimum sum of two 2-digit numbers by splitting a four-digit number into two integers.

简单
2171

拿出最少数目的魔法豆

Determine the minimum beans to remove so all remaining non-empty bags have equal beans using a greedy approach.

中等
2182

构造限制重复的字符串

Construct a lexicographically largest string from a given string with no letter appearing more than a repeatLimit times …

中等
2195

向数组中追加 K 个整数

In this problem, you need to append k unique positive integers to a given array nums such that the sum is minimized.

中等
2202

K 次操作后最大化顶端元素

Maximize the topmost element in a pile after making exactly k moves using a greedy strategy and invariant checks.

中等
2207

字符串中最多数目的子序列

Maximize the number of subsequences by optimally adding a character to a given string to match a specified pattern.

中等
2208

将数组和减半的最少操作次数

Minimize operations to halve an array's sum using greedy choices and heap data structures.

中等
2224

转化时间需要的最少操作数

The problem asks to find the minimum number of operations to convert one time string to another using specific time incr…

简单
2233

K 次增加后的最大乘积

Maximize the product of an array after performing up to k increments using a greedy approach with heap optimization.

中等
2241

设计一个 ATM 机器

Design an ATM machine that stores and withdraws money with given denominations and prioritizes larger values during with…

中等
2259

移除指定数字得到的最大结果

Determine the largest possible number by removing one specific digit using a greedy approach and string iteration.

简单
2279

装满石头的背包的最大数量

Maximize the number of bags filled to capacity by distributing additional rocks using a greedy approach.

中等
2285

道路的最大总重要性

Assign unique values to cities to maximize the total importance of all roads using greedy selection based on city connec…

中等
2294

划分数组使最大差为 K

Find the minimum number of subsequences required such that the difference between the maximum and minimum value in each …

中等
2335

装满杯子需要的最短总时长

Determine the minimum seconds to fill cups of cold, warm, and hot water using a greedy selection strategy and invariant …

简单
2366

将数组排序的最少替换次数

Minimize the number of operations to make the array sorted in non-decreasing order by replacing elements with sums of tw…

困难
2383

赢得比赛需要的最少训练时长

Find the minimum hours of training needed to beat all opponents in a competition based on energy and experience.

简单
2384

最大回文数字

Form the largest palindromic number from a string of digits while maintaining a valid palindrome structure.

中等
2405

子字符串的最优划分

Given a string s, partition it into substrings with unique characters and return the minimum number of substrings.

中等
2412

完成所有交易的初始最少钱数

Find the minimum money required to complete all transactions in any order while considering cost and cashback.

困难
2429

最小异或

Minimize XOR problem asks for an integer that minimizes XOR with another, applying greedy choices for bit manipulation.

中等
2449

使数组相似的最少操作次数

Determine the minimum operations to make two arrays similar by adjusting pairs while respecting element frequencies and …

困难
2457

美丽整数的最小增量

Find the minimum addition to a number such that its digits sum to a value less than or equal to a given target.

中等
2497

图中最大星和

Find the maximum star sum in a graph with specific node values and edges, using greedy algorithms to select the optimal …

中等
2530

执行 K 次操作后的最大分数

Maximize your score by applying exactly k operations on an array using greedy selection and heap optimization techniques…

中等
2541

使数组中所有元素相等的最小操作数 II

Calculate the minimum operations to make two integer arrays equal using greedy adjustments with modular checks efficient…

中等
2542

最大子序列的分数

Maximize the score of a subsequence by selecting indices based on nums1 and nums2, using a greedy approach and sorting.

中等
2551

将珠子放入背包中

The "Put Marbles in Bags" problem challenges you to distribute marbles into bags for maximum score difference using gree…

困难
2566

替换一个数字后的最大差值

Find the largest difference by remapping a single digit in a number using a greedy approach to maximize and minimize out…

简单
2567

修改两个元素的最小分数

The problem asks for the minimum score after changing two elements of an array using a greedy approach.

中等
2578

最小和分割

Split a positive integer into two parts to minimize their sum using a greedy approach and sorting.

简单
2587

重排数组以得到最大前缀分数

Maximize the number of positive prefix sums by rearranging an integer array using a greedy, order-focused strategy.

中等
2591

将钱分给最多的儿童

Determine the maximum number of children who can each receive exactly 8 dollars using a greedy approach with validation …

简单
2600

K 件物品的最大和

Select k items from a bag containing 1, 0, and -1 to maximize sum using greedy choice and invariant validation strategie…

简单
2607

使子数组元素和相等

Solve Make K-Subarray Sums Equal by grouping circular indices with gcd cycles and minimizing each group to its median.

中等
2611

老鼠和奶酪

In 'Mice and Cheese', you must maximize the total reward of two mice eating cheese while respecting their preferences an…

中等
2656

K 个元素的最大和

Maximize your score by performing exactly k operations on an array using a greedy approach to select the highest values.

简单
2663

字典序最小的美丽字符串

Find the lexicographically smallest beautiful string larger than the given string using greedy choice and invariant vali…

困难
2680

最大或值

Maximize the bitwise OR of an array by applying at most k multiplication operations on selected elements.

中等
2706

购买两块巧克力

Determine the leftover money after buying exactly two chocolates using a greedy selection and sum validation approach.

简单
2734

执行子串操作后的字典序最小字符串

Given a string, perform operations to make it lexicographically smaller using a greedy approach with substring modificat…

中等
2789

合并后数组中的最大元素

This problem focuses on applying greedy choices and merging elements to find the largest element in an array.

中等
2800

包含三个字符串的最短字符串

Find the shortest string containing three given strings using a greedy approach while ensuring it is lexicographically s…

中等
2829

k-avoiding 数组的最小总和

Determine the minimum sum of a k-avoiding array by choosing distinct integers such that no pair sums to a given k.

中等
2834

找出美丽数组的最小和

Find the minimum possible sum of a beautiful array that satisfies the given conditions with the greedy approach.

中等
2835

使子序列的和等于目标的最少操作次数

The problem requires finding the minimum number of operations to form a subsequence summing to a target using powers of …

困难
2842

统计一个字符串的 k 子序列美丽值最大的数目

Determine the number of k-length unique subsequences in a string that maximize the sum of character frequencies efficien…

困难
2844

生成特殊数字的最少操作

Minimize operations to make a number divisible by 25 by deleting digits. Use greedy choice and invariant validation.

中等
2864

最大二进制奇数

Rearrange a binary string to form the largest odd binary number using a greedy approach and least significant bit valida…

简单
2871

将数组分割成最多数目的子数组

Maximize the number of subarrays in an array while ensuring each subarray's bitwise AND meets the minimum score requirem…

中等
2895

最小处理时间

Determine the minimum total processing time by optimally assigning tasks to multiple processors using a greedy approach.

中等
2918

数组的最小相等和

Find the minimum sum where two arrays become equal after replacing all zeros with positive integers using a greedy strat…

中等
2931

购买物品的最大开销

Maximize spending by carefully choosing the right items across multiple shops over m * n days.

困难
2939

最大异或乘积

Find the maximum value of (a XOR x) * (b XOR x) using greedy bitwise choices and invariant validation.

中等
2952

需要添加的硬币的最小数量

Determine the minimum number of coins to add so all values up to target are obtainable using a greedy sum approach.

中等
2966

划分数组并满足最大差限制

Divide an array into subarrays with a maximum element difference under a given threshold using a greedy approach.

中等
2971

找到最大周长的多边形

Determine the largest perimeter polygon from a set of side lengths using a greedy approach with invariant validation che…

中等
3012

通过操作使数组长度最小

Minimize the length of an integer array through a series of operations, using a greedy approach with modular arithmetic.

中等
3014

输入单词需要的最少按键次数 I

Calculate the minimum pushes to type a word using a remapped telephone keypad with greedy allocation of letters.

简单
3016

输入单词需要的最少按键次数 II

Given a word, find the minimum number of pushes to type it on a remapped keypad using a greedy approach.

中等
3022

给定操作次数内使剩余元素的或值最小

Minimize the bitwise OR of the remaining elements of an array after applying at most k operations.

困难
3074

重新分装苹果

Distribute packs of apples into boxes using a greedy strategy, minimizing the number of boxes selected efficiently and c…

简单
3075

幸福值最大化的选择方案

Maximize the happiness of selected children by choosing the k happiest ones and applying greedy strategies to minimize l…

中等
3081

替换字符串中的问号使分数最小

Minimize the cost of a string with '?' characters by replacing them with letters in lexicographical order while minimizi…

中等
3085

成为 K 特殊字符串需要删除的最少字符数

Minimize deletions to make a string k-special by adjusting character frequencies.

中等
3091

执行操作使数据元素之和大于等于 K

Given an array nums, find the minimum number of operations to make the sum of elements greater than or equal to k.

中等
3106

满足距离约束且字典序最小的字符串

Minimize a string lexicographically using a series of operations constrained by a given integer k.

中等
3107

使数组中位数等于 K 的最少操作数

The problem involves minimizing operations to make the median of an array equal to a given value k using a greedy approa…

中等
3111

覆盖所有点的最少矩形数目

Find the minimum number of rectangles needed to cover all points, given constraints on width and position.

中等
3139

使数组中所有元素相等的最小开销

Compute the minimum cost to make all elements equal using selective operations guided by greedy choices and invariant ch…

困难
3207

与敌人战斗后的最大分数

Solve the "Maximum Points After Enemy Battles" problem by maximizing points through greedy choices with energy validatio…

中等
3216

交换后字典序最小的字符串

Lexicographically Smallest String After a Swap involves finding the smallest string after swapping adjacent digits with …

简单
3219

切蛋糕的最小总开销 II

Solve Minimum Cost for Cutting Cake II by choosing optimal cuts using a greedy strategy while tracking cost increments p…

困难
3228

将 1 移动到末尾的最大操作次数

This problem requires finding the maximum number of operations to move ones to the end of a binary string.

中等
3244

新增道路查询后的最短距离 II

The problem involves calculating the shortest path from city 0 to city n-1 after each road addition, leveraging greedy c…

困难
3273

对 Bob 造成的最少伤害

Minimize the total damage dealt to Bob using power to eliminate enemies efficiently with greedy approach.

困难
3282

到达数组末尾的最大得分

Calculate the maximum score to reach the end of an array using greedy jumps based on array values and distances.

中等
3301

高度互不相同的最大塔高和

Assign heights to towers ensuring each height is unique and the total sum is maximized using greedy sorting techniques.

中等
3326

使数组非递减的最少除法操作次数

Determine the minimum number of division operations to make an array non-decreasing using a greedy and invariant-based s…

中等
3362

零数组变换 III

Zero Array Transformation III requires removing the minimum number of queries to make all elements zero using greedy val…

中等
3397

执行操作后不同元素的最大数量

Maximize distinct elements in an array by performing at most one operation on each element.

中等
3402

使每一列严格递增的最少操作次数

Calculate the minimum increments to make each column of a matrix strictly increasing using a greedy invariant approach.

简单
3424

将数组变相同的最小代价

Minimize cost to make arrays identical by performing operations with given constraints and a greedy strategy.

中等
3440

重新安排会议得到最多空余时间 II

Maximize free time by rescheduling at most one meeting using a greedy choice with invariant validation approach for arra…

中等
3457

吃披萨

Maximize the total weight gained by optimally eating pizzas in groups of four using greedy selection and invariant valid…

中等
3462

提取至多 K 个元素的最大总和

Find the maximum sum by selecting at most k elements from a 2D matrix respecting per-row limits using a greedy strategy.

中等
3474

字典序最小的生成字符串

Generate the lexicographically smallest string by merging str1 and str2 using a greedy approach with invariant checks.

困难
3545

不同字符数量最多为 K 时的最少删除数

You need to delete characters in a string to reduce its distinct characters to at most k.

简单
3576

数组元素相等转换

Transform Array to All Equal Elements requires careful greedy choices and validating invariants to achieve uniformity ef…

中等
3587

最小相邻交换至奇偶交替

Compute the minimum adjacent swaps to make array elements alternate between even and odd using greedy and invariant chec…

中等
3630

划分数组得到最大异或运算和与运算之和

Partition the array into three subsequences to maximize XOR and AND operations with a greedy approach.

困难

关联题型

LeetCode 贪心·invariant模式题解:198题训练路线