LeetCodechevron_rightgreedy invariant

greedy invariant Pattern

198 problems

Pattern pages help build reusable solving frames. Identify signals first, then explain state, transition, and edge handling.

Recognition Signals

  • 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.

Solve Flow

  1. 1. Define the active state/window.
  2. 2. Update state while preserving invariants.
  3. 3. Validate with edge-heavy examples.

Common Misses

  • 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.

Recommended Ladder

#TitleDifficulty
134

Gas Station

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

Medium
135

Candy

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

Hard
179

Largest Number

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

Medium
324

Wiggle Sort II

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

Medium
330

Patching Array

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

Hard
334

Increasing Triplet Subsequence

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

Medium
409

Longest Palindrome

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

Easy
420

Strong Password Checker

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

Hard
452

Minimum Number of Arrows to Burst Balloons

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

Medium
502

IPO

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

Hard
517

Super Washing Machines

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

Hard
561

Array Partition

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

Easy
605

Can Place Flowers

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

Easy
624

Maximum Distance in Arrays

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

Medium
630

Course Schedule III

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

Hard
670

Maximum Swap

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

Medium
738

Monotone Increasing Digits

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

Medium
757

Set Intersection Size At Least Two

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

Hard
767

Reorganize String

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

Medium
807

Max Increase to Keep City Skyline

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

Medium
857

Minimum Cost to Hire K Workers

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

Hard
860

Lemonade Change

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

Easy
861

Score After Flipping Matrix

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

Medium
910

Smallest Range II

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

Medium
945

Minimum Increment to Make Array Unique

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

Medium
955

Delete Columns to Make Sorted II

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

Medium
976

Largest Perimeter Triangle

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

Easy
984

String Without AAA or BBB

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

Medium
991

Broken Calculator

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

Medium
1005

Maximize Sum Of Array After K Negations

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

Easy
1007

Minimum Domino Rotations For Equal Row

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

Medium
1013

Partition Array Into Three Parts With Equal Sum

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

Easy
1029

Two City Scheduling

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

Medium
1053

Previous Permutation With One Swap

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

Medium
1144

Decrease Elements To Make Array Zigzag

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

Medium
1217

Minimum Cost to Move Chips to The Same Position

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

Easy
1221

Split a String in Balanced Strings

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

Easy
1247

Minimum Swaps to Make Strings Equal

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

Medium
1253

Reconstruct a 2-Row Binary Matrix

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

Medium
1323

Maximum 69 Number

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

Easy
1328

Break a Palindrome

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

Medium
1330

Reverse Subarray To Maximize Array Value

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

Hard
1353

Maximum Number of Events That Can Be Attended

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

Medium
1383

Maximum Performance of a Team

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

Hard
1400

Construct K Palindrome Strings

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

Medium
1403

Minimum Subsequence in Non-Increasing Order

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

Easy
1405

Longest Happy String

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

Medium
1414

Find the Minimum Number of Fibonacci Numbers Whose Sum Is K

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

Medium
1432

Max Difference You Can Get From Changing an Integer

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

Medium
1433

Check If a String Can Break Another String

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

Medium
1465

Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts

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

Medium
1505

Minimum Possible Integer After at Most K Adjacent Swaps On Digits

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

Hard
1509

Minimum Difference Between Largest and Smallest Value in Three Moves

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

Medium
1520

Maximum Number of Non-Overlapping Substrings

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

Hard
1529

Minimum Suffix Flips

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

Medium
1536

Minimum Swaps to Arrange a Binary Grid

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

Medium
1558

Minimum Numbers of Function Calls to Make Target Array

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

Medium
1561

Maximum Number of Coins You Can Get

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

Medium
1585

Check If String Is Transformable With Substring Sort Operations

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

Hard
1589

Maximum Sum Obtained of Any Permutation

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

Medium
1605

Find Valid Matrix Given Row and Column Sums

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

Medium
1606

Find Servers That Handled Most Number of Requests

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

Hard
1642

Furthest Building You Can Reach

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

Medium
1647

Minimum Deletions to Make Character Frequencies Unique

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

Medium
1663

Smallest String With A Given Numeric Value

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

Medium
1665

Minimum Initial Energy to Finish Tasks

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

Hard
1675

Minimize Deviation in Array

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

Hard
1686

Stone Game VI

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

Medium
1689

Partitioning Into Minimum Number Of Deci-Binary Numbers

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

Medium
1702

Maximum Binary String After Change

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

Medium
1705

Maximum Number of Eaten Apples

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

Medium
1710

Maximum Units on a Truck

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

Easy
1727

Largest Submatrix With Rearrangements

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

Medium
1736

Latest Time by Replacing Hidden Digits

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

Easy
1753

Maximum Score From Removing Stones

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

Medium
1785

Minimum Elements to Add to Form a Given Sum

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

Medium
1792

Maximum Average Pass Ratio

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

Medium
1798

Maximum Number of Consecutive Values You Can Make

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

Medium
1827

Minimum Operations to Make the Array Increasing

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

Easy
1833

Maximum Ice Cream Bars

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

Medium
1846

Maximum Element After Decreasing and Rearranging

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

Medium
1864

Minimum Number of Swaps to Make the Binary String Alternating

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

Medium
1881

Maximum Value after Insertion

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

Medium
1899

Merge Triplets to Form Target Triplet

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

Medium
1903

Largest Odd Number in String

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

Easy
1921

Eliminate Maximum Number of Monsters

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

Medium
1927

Sum Game

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

Medium
1936

Add Minimum Number of Rungs

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

Medium
1946

Largest Number After Mutating Substring

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

Medium
1953

Maximum Number of Weeks for Which You Can Work

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

Medium
1962

Remove Stones to Minimize the Total

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

Medium
1968

Array With Elements Not Equal to Average of Neighbors

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

Medium
1969

Minimum Non-Zero Product of the Array Elements

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

Medium
1974

Minimum Time to Type Word Using Special Typewriter

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

Easy
1975

Maximum Matrix Sum

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

Medium
2027

Minimum Moves to Convert String

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

Easy
2029

Stone Game 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…

Medium
2037

Minimum Number of Moves to Seat Everyone

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

Easy
2038

Remove Colored Pieces if Both Neighbors are the Same Color

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

Medium
2078

Two Furthest Houses With Different Colors

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

Easy
2087

Minimum Cost Homecoming of a Robot in a Grid

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

Medium
2091

Removing Minimum and Maximum From Array

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

Medium
2126

Destroying Asteroids

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

Medium
2132

Stamping the Grid

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

Hard
2136

Earliest Possible Day of Full Bloom

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

Hard
2139

Minimum Moves to Reach Target Score

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

Medium
2144

Minimum Cost of Buying Candies With Discount

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

Easy
2160

Minimum Sum of Four Digit Number After Splitting Digits

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

Easy
2171

Removing Minimum Number of Magic Beans

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

Medium
2182

Construct String With Repeat Limit

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

Medium
2195

Append K Integers With Minimal Sum

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

Medium
2202

Maximize the Topmost Element After K Moves

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

Medium
2207

Maximize Number of Subsequences in a String

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

Medium
2208

Minimum Operations to Halve Array Sum

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

Medium
2224

Minimum Number of Operations to Convert Time

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

Easy
2233

Maximum Product After K Increments

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

Medium
2241

Design an ATM Machine

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

Medium
2259

Remove Digit From Number to Maximize Result

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

Easy
2279

Maximum Bags With Full Capacity of Rocks

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

Medium
2285

Maximum Total Importance of Roads

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

Medium
2294

Partition Array Such That Maximum Difference Is K

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

Medium
2335

Minimum Amount of Time to Fill Cups

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

Easy
2366

Minimum Replacements to Sort the Array

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

Hard
2383

Minimum Hours of Training to Win a Competition

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

Easy
2384

Largest Palindromic Number

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

Medium
2405

Optimal Partition of String

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

Medium
2412

Minimum Money Required Before Transactions

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

Hard
2429

Minimize XOR

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

Medium
2449

Minimum Number of Operations to Make Arrays Similar

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

Hard
2457

Minimum Addition to Make Integer Beautiful

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

Medium
2497

Maximum Star Sum of a Graph

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

Medium
2530

Maximal Score After Applying K Operations

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

Medium
2541

Minimum Operations to Make Array Equal II

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

Medium
2542

Maximum Subsequence Score

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

Medium
2551

Put Marbles in Bags

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

Hard
2566

Maximum Difference by Remapping a Digit

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

Easy
2567

Minimum Score by Changing Two Elements

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

Medium
2578

Split With Minimum Sum

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

Easy
2587

Rearrange Array to Maximize Prefix Score

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

Medium
2591

Distribute Money to Maximum Children

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

Easy
2600

K Items With the Maximum Sum

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

Easy
2607

Make K-Subarray Sums Equal

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

Medium
2611

Mice and Cheese

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

Medium
2656

Maximum Sum With Exactly K Elements

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

Easy
2663

Lexicographically Smallest Beautiful String

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

Hard
2680

Maximum OR

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

Medium
2706

Buy Two Chocolates

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

Easy
2734

Lexicographically Smallest String After Substring Operation

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

Medium
2789

Largest Element in an Array after Merge Operations

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

Medium
2800

Shortest String That Contains Three Strings

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

Medium
2829

Determine the Minimum Sum of a k-avoiding Array

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

Medium
2834

Find the Minimum Possible Sum of a Beautiful Array

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

Medium
2835

Minimum Operations to Form Subsequence With Target Sum

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

Hard
2842

Count K-Subsequences of a String With Maximum Beauty

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

Hard
2844

Minimum Operations to Make a Special Number

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

Medium
2864

Maximum Odd Binary Number

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

Easy
2871

Split Array Into Maximum Number of Subarrays

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

Medium
2895

Minimum Processing Time

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

Medium
2918

Minimum Equal Sum of Two Arrays After Replacing Zeros

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

Medium
2931

Maximum Spending After Buying Items

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

Hard
2939

Maximum Xor Product

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

Medium
2952

Minimum Number of Coins to be Added

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

Medium
2966

Divide Array Into Arrays With Max Difference

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

Medium
2971

Find Polygon With the Largest Perimeter

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

Medium
3012

Minimize Length of Array Using Operations

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

Medium
3014

Minimum Number of Pushes to Type Word I

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

Easy
3016

Minimum Number of Pushes to Type Word II

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

Medium
3022

Minimize OR of Remaining Elements Using Operations

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

Hard
3074

Apple Redistribution into Boxes

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

Easy
3075

Maximize Happiness of Selected Children

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

Medium
3081

Replace Question Marks in String to Minimize Its Value

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

Medium
3085

Minimum Deletions to Make String K-Special

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

Medium
3091

Apply Operations to Make Sum of Array Greater Than or Equal to k

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

Medium
3106

Lexicographically Smallest String After Operations With Constraint

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

Medium
3107

Minimum Operations to Make Median of Array Equal to K

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

Medium
3111

Minimum Rectangles to Cover Points

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

Medium
3139

Minimum Cost to Equalize Array

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

Hard
3207

Maximum Points After Enemy Battles

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

Medium
3216

Lexicographically Smallest String After a Swap

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

Easy
3219

Minimum Cost for Cutting Cake II

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

Hard
3228

Maximum Number of Operations to Move Ones to the End

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

Medium
3244

Shortest Distance After Road Addition Queries II

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

Hard
3273

Minimum Amount of Damage Dealt to Bob

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

Hard
3282

Reach End of Array With Max Score

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

Medium
3301

Maximize the Total Height of Unique Towers

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

Medium
3326

Minimum Division Operations to Make Array Non Decreasing

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

Medium
3362

Zero Array Transformation III

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

Medium
3397

Maximum Number of Distinct Elements After Operations

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

Medium
3402

Minimum Operations to Make Columns Strictly Increasing

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

Easy
3424

Minimum Cost to Make Arrays Identical

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

Medium
3440

Reschedule Meetings for Maximum Free Time II

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

Medium
3457

Eat Pizzas!

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

Medium
3462

Maximum Sum With at Most K Elements

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

Medium
3474

Lexicographically Smallest Generated String

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

Hard
3545

Minimum Deletions for At Most K Distinct Characters

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

Easy
3576

Transform Array to All Equal Elements

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

Medium
3587

Minimum Adjacent Swaps to Alternate Parity

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

Medium
3630

Partition Array for Maximum XOR and AND

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

Hard

Related Topics

Greedy choice plus invariant validation LeetCode Pattern: 198 Solutions