greedy
greedy is one of the most repeated interview dimensions. Start with edge-safe fundamentals, then move into pattern-level trade-offs.
Interview Signal
Frequently tests problem modeling, edge handling, and verbal clarity.
Common Pitfall
Template-only answers break under follow-up questioning.
Practice Strategy
Practice in 3-5 problem rounds and always review complexity alternatives.
Recommended Progression
Pattern Bridge
High-Pressure Round
Container With Most Water
Find two vertical lines that can form a container with the most water in a given array of heights.
Wildcard Matching
Implement full wildcard pattern matching using '?' and '*' by applying state transition dynamic programming with careful…
Jump Game II
Jump Game II requires finding the minimum jumps to reach the end of an array using dynamic programming and greedy techni…
Jump Game
Solve the Jump Game problem using state transition dynamic programming to determine if you can reach the last index of t…
Best Time to Buy and Sell Stock II
Maximize stock profit by using a greedy approach to buy and sell multiple times, with state transition dynamic programmi…
Gas Station
The Gas Station problem requires finding the starting station index for a full circular trip with gas stations and costs…
Candy
The Candy problem is a greedy algorithm challenge where you need to minimize candy distribution while satisfying certain…
Largest Number
The problem asks to arrange integers to form the largest possible number, focusing on greedy algorithms and string handl…
Remove Duplicate Letters
Remove duplicate letters from a string to produce the lexicographically smallest result using stack-based state manageme…
Create Maximum Number
Create Maximum Number involves merging digits from two arrays while preserving order, maximizing the resulting number.
Wiggle Sort II
Rearrange an array in a way that every odd-indexed element is greater than its adjacent even-indexed elements.
Patching Array
Patching Array requires adding the minimum numbers to cover all sums from 1 to n using greedy choices and invariant chec…
Increasing Triplet Subsequence
Identify if an array contains a strictly increasing triplet by maintaining a running minimal and middle value efficientl…
Wiggle Subsequence
Find the longest wiggle subsequence in an integer array using state transition dynamic programming with greedy optimizat…
Integer Replacement
Find the minimum number of operations to reduce a number to 1 by applying specific operations, using state transition dy…
Remove K Digits
Remove K Digits requires selecting which digits to drop using a monotonic stack for the smallest possible integer result…
Longest Palindrome
Determine the length of the longest palindrome constructible from a given string using greedy counting and frequency tra…
Split Array Largest Sum
Solve the 'Split Array Largest Sum' problem by minimizing the largest sum across k subarrays using dynamic programming a…
Strong Password Checker
The Strong Password Checker problem challenges you to optimize password strength while minimizing steps using greedy alg…
Non-overlapping Intervals
Determine the minimum number of intervals to remove from a list to ensure no intervals overlap using dynamic programming…
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.
Assign Cookies
Maximize content children by assigning at most one cookie per child using two-pointer scanning and greedy sorting techni…
IPO
Maximize total capital by selecting up to k projects, based on initial capital and project profits using a greedy strate…
Super Washing Machines
Calculate the minimum moves to balance dresses across washing machines using a greedy strategy and invariant validation …
Array Partition
Maximize the sum of minimums of n pairs in a 2n integer array using a greedy pairing strategy efficiently.
Shortest Unsorted Continuous Subarray
Find the shortest unsorted continuous subarray that, if sorted, would sort the entire array.
Can Place Flowers
Determine if n new flowers can be planted in a flowerbed, ensuring no adjacent flowers using a greedy approach.
Valid Triangle Number
Count all triplets in an integer array that satisfy the triangle inequality to form valid triangles efficiently using so…
Task Scheduler
Task Scheduler is solved by counting task frequencies and computing how cooldown gaps force idle slots around the most f…
Maximum Distance in Arrays
Maximum Distance in Arrays uses a greedy running minimum and maximum from previous arrays to validate cross array distan…
Course Schedule III
Solve the 'Course Schedule III' problem with a greedy approach involving course selection and validation of constraints.
Smallest Range Covering Elements from K Lists
Find the minimal range covering at least one number from each of k sorted lists using array scanning and hash lookup eff…
Maximum Length of Pair Chain
Determine the maximum length of a chain formed by pairs using dynamic programming and greedy sorting techniques efficien…
Dota2 Senate
The Dota2 Senate problem involves simulating voting rounds between Radiant and Dire senators until one party wins, using…
Split Array into Consecutive Subsequences
Verify if it's possible to split a sorted array into consecutive subsequences of length 3 or more.
Maximum Swap
Given an integer, swap at most two digits once to produce the largest possible number using greedy digit selection.
Valid Parenthesis String
Solve the Valid Parenthesis String problem by leveraging state transition dynamic programming to handle parentheses and …
Valid Palindrome II
Check if a string can become a palindrome by deleting at most one character using two-pointer scanning and invariant tra…
Best Time to Buy and Sell Stock with Transaction Fee
Maximize stock trading profits accounting for per-transaction fees using state transition dynamic programming and greedy…
Monotone Increasing Digits
Determine the largest number less than or equal to n with digits in non-decreasing order using a greedy, invariant-drive…
Set Intersection Size At Least Two
Solve the Set Intersection Size At Least Two problem using a greedy approach and invariant validation.
Partition Labels
Partition a string into maximal parts so that each letter appears in only one segment, using two-pointer scanning.
Couples Holding Hands
This problem requires arranging couples sitting apart in a row with the minimum number of swaps using graph traversal an…
Reorganize String
Reorganize a string so that no two adjacent characters are the same, if possible, using a greedy approach.
Max Chunks To Make Sorted II
Determine the maximum number of chunks you can split an array into so that sorting each chunk results in a fully sorted …
Max Chunks To Make Sorted
The Max Chunks To Make Sorted problem requires you to split an array into the maximum number of chunks that can be sorte…
Rabbits in Forest
Solve Rabbits in Forest by grouping equal answers and rounding each group into the smallest valid color-class size.
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…
Most Profit Assigning Work
Assign workers to jobs maximizing total profit using difficulty, profit, and worker arrays efficiently with binary searc…
Hand of Straights
Check if a hand of cards can be rearranged into groups of consecutive values.
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…
Lemonade Change
Determine if you can provide exact change to every customer at a lemonade stand using greedy bill management techniques.
Score After Flipping Matrix
Maximize the score of a binary matrix by flipping rows and columns using a greedy approach and validation of invariants.
Advantage Shuffle
Maximize the advantage of nums1 over nums2 using a two-pointer greedy strategy, carefully tracking which elements beat o…
Minimum Number of Refueling Stops
Determine the minimum number of refueling stops needed to reach a target using dynamic programming and greedy strategies…
Boats to Save People
Find the minimum number of boats required to save all people, using a two-pointer approach for efficient pairing.
Smallest Range II
Determine the minimum possible difference between the largest and smallest numbers after adjusting each by plus or minus…
Minimum Add to Make Parentheses Valid
Compute the minimum insertions needed to make a parentheses string valid using efficient stack-based state tracking tech…
Stamping The Sequence
Solve Stamping The Sequence with stack-based state management to convert string s to target using stamp efficiently.
DI String Match
Reconstruct a permutation from a DI string using two-pointer scanning, carefully tracking the increasing and decreasing …
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.
Bag of Tokens
Maximize your score in the Bag of Tokens problem by strategically playing tokens with two-pointer scanning and greedy te…
Array of Doubled Pairs
Given an array of even length, check if it can be reordered to satisfy a specific doubling condition.
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…
Pancake Sorting
Sort an array using pancake flips, leveraging two-pointer scanning and invariant tracking to iteratively position the la…
Largest Perimeter Triangle
Given an integer array, find the largest perimeter of a triangle formed from three of these lengths.
String Without AAA or BBB
Solve the problem of constructing a string without consecutive 'AAA' or 'BBB' by applying a greedy approach with invaria…
Broken Calculator
Compute the minimum operations to transform startValue into target using doubling and decrementing, leveraging a greedy …
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…
Minimum Domino Rotations For Equal Row
Minimize domino rotations to make either row identical in the problem of Minimum Domino Rotations For Equal Row.
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.
Video Stitching
Solve the "Video Stitching" problem using state transition dynamic programming to cover a sporting event with minimum cl…
Two City Scheduling
Two City Scheduling requires selecting optimal city assignments for 2n people to minimize total travel costs efficiently…
Previous Permutation With One Swap
Find the lexicographically largest permutation smaller than the given array using exactly one swap, leveraging a greedy …
Distant Barcodes
Rearrange barcodes in an array so that no two adjacent elements are equal, using a greedy approach and hash table for ef…
Smallest Subsequence of Distinct Characters
The Smallest Subsequence of Distinct Characters problem asks you to find the lexicographically smallest subsequence of a…
Largest Values From Labels
Maximize the sum of selected item values while respecting label use limits using array scanning and hash tracking.
Minimum Cost Tree From Leaf Values
Compute the minimum sum of non-leaf nodes in a binary tree formed from array leaves using dynamic programming efficientl…
Decrease Elements To Make Array Zigzag
Transform any integer array into a zigzag pattern with minimal decrements using a targeted greedy approach and invariant…
Longest Chunked Palindrome Decomposition
Solve the "Longest Chunked Palindrome Decomposition" problem by using dynamic programming and string manipulation techni…
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.
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'.
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…
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…
Greatest Sum Divisible by Three
Find the maximum sum divisible by three from a given array using dynamic programming and state transition.
Group the People Given the Group Size They Belong To
Organize people into groups based on their specified group sizes using array scanning and hash table bucketing efficient…
Divide Array in Sets of K Consecutive Numbers
Determine if an integer array can be partitioned into sets of k consecutive numbers using array scanning and hash mappin…
Maximum 69 Number
Maximize a number by flipping at most one digit from 6 to 9 or vice versa.
Minimum Number of Taps to Open to Water a Garden
Determine the minimum number of taps to water an entire garden using state transition dynamic programming and interval c…
Break a Palindrome
Given a palindrome, change exactly one character to make it non-palindromic and lexicographically smallest using a greed…
Reverse Subarray To Maximize Array Value
Maximize the value of an array by reversing a subarray, focusing on greedy choices and invariant validation.
Reduce Array Size to The Half
This problem asks to minimize the set of integers removed to reduce an array's size to at least half by removing occurre…
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.
Largest Multiple of Three
Find the largest number divisible by three by selecting and ordering digits optimally using state transition dynamic pro…
Balance a Binary Search Tree
This problem requires balancing a binary search tree using in-order traversal and state tracking techniques.
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…
Cinema Seat Allocation
Determine the maximum number of four-person groups that can be seated in a cinema using array scanning and hash lookup e…
Pizza With 3n Slices
Maximize your pizza slice sum from a 3n-sized circular array using state transition dynamic programming efficiently.
Construct K Palindrome Strings
Determine if a string's characters can be rearranged to form exactly k non-empty palindrome strings using greedy validat…
Reducing Dishes
Maximize the sum of like-time coefficients by optimally choosing dishes to prepare in this dynamic programming problem.
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.
Longest Happy String
Solve the "Longest Happy String" problem using a greedy approach with validation of invariants for constructing the long…
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.
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.
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.
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.
Least Number of Unique Integers after K Removals
Find the least number of unique integers after removing exactly k elements from an array using efficient frequency count…
Avoid Flood in The City
This problem asks you to avoid flooding by deciding when to dry lakes between rain events.
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…
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.
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…
Minimum Number of Increments on Subarrays to Form a Target Array
The problem asks for the minimum number of operations to transform an initial array of zeros into a target array using s…
Minimum Suffix Flips
Find the minimum number of operations to convert a binary string to a target string using bit flips.
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…
Get the Maximum Score
Find the maximum possible score from two sorted arrays with a dynamic programming approach, leveraging partitioning and …
Minimum Insertions to Balance a Parentheses String
Compute the minimum insertions to transform a parentheses string into a balanced string using efficient stack tracking.
Maximum Number of Non-Overlapping Subarrays With Sum Equals Target
Find the maximum number of non-overlapping subarrays that sum to a given target using efficient scanning and hash lookup…
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 …
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…
Maximum Length of Subarray With Positive Product
Given an array, find the maximum length of a subarray with a positive product using dynamic programming.
Minimum Time to Make Rope Colorful
Minimize the time Bob needs to remove balloons to make a rope colorful using dynamic programming with state transitions.
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.
Maximum Sum Obtained of Any Permutation
Maximize the total sum of requests on nums by greedily assigning larger numbers to most frequently requested indices.
Find Valid Matrix Given Row and Column Sums
Given row and column sums, find any valid matrix of non-negative integers that satisfies them.
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…
Furthest Building You Can Reach
Furthest Building You Can Reach explores a greedy approach with heap-based optimization to find the maximum reachable bu…
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…
Sell Diminishing-Valued Colored Balls
Maximize total value by greedily selling diminishing-valued colored balls based on inventory and customer orders.
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.
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 …
Minimum Number of Removals to Make Mountain Array
Solve the problem of finding the minimum number of removals to make a given array a mountain array using dynamic program…
Find the Most Competitive Subsequence
Identify the lexicographically smallest subsequence of size k using stack-based greedy selection in array traversal.
Minimize Deviation in Array
Given a positive integer array, repeatedly double or halve elements to minimize the difference between its largest and s…
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 …
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…
Maximum Binary String After Change
The problem asks to maximize a binary string using specific operations to get the highest possible value.
Minimum Adjacent Swaps for K Consecutive Ones
Find the minimum number of adjacent swaps to gather k consecutive ones in a binary array using sliding window logic.
Maximum Number of Eaten Apples
Maximize apples eaten by choosing the best apples first, considering their rot days and available days to eat them.
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…
Minimum Operations to Make a Subsequence
Compute the minimum insertions required to transform arr so that target becomes its subsequence using array scanning and…
Maximum Score From Removing Substrings
Compute the highest score by greedily removing specific substrings using a stack to track state transitions efficiently.
Largest Submatrix With Rearrangements
Rearrange columns of a binary matrix to find the largest submatrix of 1s.
Minimum Number of People to Teach
Minimize the number of users to teach a language that ensures all friends can communicate in a social network.
Latest Time by Replacing Hidden Digits
Determine the latest valid time by replacing hidden digits using a greedy choice and invariant validation strategy effic…
Building Boxes
Optimize the number of boxes touching the floor in a cubic room using binary search to minimize floor occupancy.
Maximum Score From Removing Stones
Maximize the score in a solitaire game by optimally removing stones from three piles with a greedy approach.
Largest Merge Of Two Strings
Construct the lexicographically largest merge from two strings using a two-pointer greedy scanning approach efficiently.
Form Array by Concatenating Subarrays of Another Array
Determine if you can sequentially select disjoint subarrays from nums matching each group in order using two-pointer sca…
Equal Sum Arrays With Minimum Number of Operations
Solve the problem of balancing the sums of two integer arrays with minimal operations, using array scanning and hash loo…
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…
Maximum Average Pass Ratio
Maximize the average pass ratio by assigning extra guaranteed-passing students using a greedy heap strategy for optimal …
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.
Maximum Value at a Given Index in a Bounded Array
Maximize the value at a given index of an array with constraints using binary search over the valid answer space.
Minimum Sideway Jumps
Solve the Minimum Sideway Jumps problem using state transition dynamic programming to minimize side jumps while navigati…
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…
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.
Frequency of the Most Frequent Element
Maximize the frequency of an element in an array by incrementing at most `k` elements. Use binary search and greedy tech…
Maximum Element After Decreasing and Rearranging
Determine the maximum value in an array after decreasing elements and rearranging using a greedy invariant approach.
Minimum Adjacent Swaps to Reach the Kth Smallest Number
Find the minimum number of adjacent swaps to reach the kth smallest wonderful integer from a given number string.
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…
Minimize Maximum Pair Sum in Array
Minimize the maximum pair sum in an array by optimally pairing its elements.
Maximum Value after Insertion
Solve Maximum Value after Insertion by greedily placing x at the first digit that makes the resulting signed number larg…
Merge Triplets to Form Target Triplet
Determine if target triplet can be formed by merging given triplets using greedy selection and invariant checks.
Largest Odd Number in String
Find the largest odd number in a string using a greedy approach with careful digit inspection and invariant checks.
Eliminate Maximum Number of Monsters
Eliminate monsters by strategically using a weapon in a video game to stop them before they reach your city.
Sum Game
Determine if Alice can force a win in the Sum Game by strategically replacing '?' using a greedy and invariant approach.
Add Minimum Number of Rungs
Determine the fewest rungs to add to climb a strictly increasing ladder using a greedy step-by-step approach.
Largest Number After Mutating Substring
Find the largest integer by mutating a substring of a number using a mapping array for each digit.
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…
Remove Stones to Minimize the Total
Minimize the total stones by repeatedly removing half from the largest pile using a greedy heap strategy.
Minimum Number of Swaps to Make the String Balanced
Determine the minimum swaps to balance a bracket string using two-pointer scanning with invariant tracking efficiently.
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.
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…
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…
Maximum Matrix Sum
Maximize the sum of an n x n integer matrix using row and column negation operations efficiently with a greedy approach.
The Number of Weak Characters in the Game
Identify all weak characters in a game by analyzing attack and defense values using a stack-based greedy sorting approac…
Find Original Array From Doubled Array
Given a shuffled array, determine if it is a doubled array and find the original array.
Longest Subsequence Repeated k Times
Find the longest subsequence repeated k times in a string using backtracking search with pruning.
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'.
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…
Smallest K-Length Subsequence With Occurrences of a Letter
Find the lexicographically smallest subsequence of length k with at least repetition occurrences of a given letter using…
Minimum Number of Moves to Seat Everyone
Calculate the minimum total moves to seat each student using greedy assignment and invariant validation efficiently.
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.
Minimized Maximum of Products Distributed to Any Store
Distribute products to stores so the largest store allocation is minimized using binary search over possible maximums.
Maximum Number of Tasks You Can Assign
Maximize the number of tasks that can be completed by efficiently using workers and magical pills.
Two Furthest Houses With Different Colors
Maximize the distance between two houses with different colors by using a greedy approach and validating the choice.
Minimum Number of Food Buckets to Feed the Hamsters
Find the minimum number of food buckets required to feed all hamsters, using dynamic programming and greedy techniques.
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.
Removing Minimum and Maximum From Array
The problem asks to remove the minimum and maximum elements from an array with the fewest deletions.
Check if a Parentheses String Can Be Valid
Determine if a parentheses string can be transformed into a valid sequence considering locked positions using stack logi…
Destroying Asteroids
This problem requires destroying asteroids by choosing the right order of collisions based on mass, using a greedy appro…
Longest Palindrome by Concatenating Two Letter Words
Find the maximum-length palindrome by combining two-letter words using array scanning and hash table lookups efficiently…
Stamping the Grid
Determine if a binary grid can be fully covered using fixed-size stamps by applying a greedy placement and validation st…
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…
Minimum Moves to Reach Target Score
Calculate the fewest steps to reach a target integer using increments and limited doubles with a greedy strategy.
Maximum Running Time of N Computers
Solve the problem of determining the maximum running time of n computers using a set of batteries.
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.
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.
Minimum Operations to Make the Array Alternating
Given an array, calculate the minimum number of operations needed to make it alternating.
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.
Maximum Split of Positive Even Integers
Determine the largest set of unique positive even integers that sum to a given finalSum using backtracking and greedy se…
Construct String With Repeat Limit
Construct a lexicographically largest string from a given string with no letter appearing more than a repeatLimit times …
Minimum Number of Moves to Make Palindrome
The problem challenges you to find the minimum number of adjacent swaps to make a string a palindrome.
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.
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.
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.
Minimum Operations to Halve Array Sum
Minimize operations to halve an array's sum using greedy choices and heap data structures.
Minimum Deletions to Make Array Beautiful
Determine the minimum deletions required to transform an array into a beautiful sequence using stack-based state managem…
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…
Maximum Product After K Increments
Maximize the product of an array after performing up to k increments using a greedy approach with heap optimization.
Maximum Total Beauty of the Gardens
Determine the maximum total beauty of gardens by strategically planting flowers using binary search over achievable flow…
Design an ATM Machine
Design an ATM machine that stores and withdraws money with given denominations and prioritizes larger values during with…
Minimum Rounds to Complete All Tasks
The problem requires finding the minimum rounds to complete tasks, focusing on greedy algorithms and hash table lookups.
Remove Digit From Number to Maximize Result
Determine the largest possible number by removing one specific digit using a greedy approach and string iteration.
Maximum White Tiles Covered by a Carpet
Solve Maximum White Tiles Covered by a Carpet by sorting intervals, checking optimal carpet starts, and counting full pl…
Maximum Bags With Full Capacity of Rocks
Maximize the number of bags filled to capacity by distributing additional rocks using a greedy approach.
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…
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 …
Sum of Numbers With Units Digit K
Determine the minimum set of positive integers whose units digits match k and sum exactly to num using DP patterns.
Longest Binary Subsequence Less Than or Equal to K
Find the longest subsequence in a binary string that forms a number less than or equal to a given integer k.
Minimum Sum of Squared Difference
Calculate the minimum sum of squared differences between two arrays using limited modifications and binary search techni…
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 …
Shortest Impossible Sequence of Rolls
Find the shortest subsequence that cannot be formed from a sequence of dice rolls, with efficient array scanning and has…
Make Array Zero by Subtracting Equal Amounts
Minimize operations to make all array elements zero by subtracting equal amounts in each operation.
Maximum Number of Groups Entering a Competition
Determine the maximum number of ordered non-empty student groups for a competition using grades array analysis and binar…
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…
Construct Smallest Number From DI String
Construct the lexicographically smallest string that fits the increasing and decreasing conditions of a given pattern.
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.
Largest Palindromic Number
Form the largest palindromic number from a string of digits while maintaining a valid palindrome structure.
Longest Subsequence With Limited Sum
Find the maximum size of a subsequence from nums with a sum less than or equal to each query value.
Optimal Partition of String
Given a string s, partition it into substrings with unique characters and return the minimum number of substrings.
Divide Intervals Into Minimum Number of Groups
Determine the minimum number of non-overlapping groups for a set of intervals using precise two-pointer scanning logic.
Maximum Matching of Players With Trainers
Maximize the number of valid player-trainer matchings using two-pointer scanning and careful sorting strategy.
Minimum Money Required Before Transactions
Find the minimum money required to complete all transactions in any order while considering cost and cashback.
Minimize XOR
Minimize XOR problem asks for an integer that minimizes XOR with another, applying greedy choices for bit manipulation.
Using a Robot to Print the Lexicographically Smallest String
Solve the problem of using a robot to print the lexicographically smallest string with stack-based state management.
Minimize Maximum of Array
Minimize Maximum of Array involves finding the smallest possible maximum value after applying a series of operations on …
Minimum Cost to Make Array Equal
Find the minimum cost to make all elements of an array equal by using binary search over valid answers.
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 …
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.
Maximum Number of Non-overlapping Palindrome Substrings
Find the maximum number of non-overlapping palindromic substrings of at least length k in a string using dynamic program…
Append Characters to String to Make Subsequence
Determine the minimum characters to append to s so t becomes a subsequence using efficient two-pointer scanning techniqu…
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 …
Frog Jump II
Frog Jump II requires finding the minimal maximum jump length for a frog to traverse stones forward and backward efficie…
Minimum Total Cost to Make Arrays Unequal
Calculate the minimum cost to rearrange nums1 so that no element matches nums2 using optimal swaps and hash counting.
Maximum Tastiness of Candy Basket
Maximize the tastiness of a candy basket by choosing k candies from a list of candy prices.
Partition String Into Substrings With Values at Most K
Determine the minimum number of substrings from a numeric string such that each substring value does not exceed k using …
Maximize the Minimum Powered City
Determine the maximum minimum power a city can achieve by strategically adding power stations using binary search and pr…
Maximal Score After Applying K Operations
Maximize your score by applying exactly k operations on an array using greedy selection and heap optimization techniques…
Minimum Operations to Make Array Equal II
Calculate the minimum operations to make two integer arrays equal using greedy adjustments with modular checks efficient…
Maximum Subsequence Score
Maximize the score of a subsequence by selecting indices based on nums1 and nums2, using a greedy approach and sorting.
Put Marbles in Bags
The "Put Marbles in Bags" problem challenges you to distribute marbles into bags for maximum score difference using gree…
Maximum Number of Integers to Choose From a Range I
Determine the maximum count of integers from 1 to n avoiding banned numbers while keeping the sum under maxSum.
House Robber IV
House Robber IV requires calculating minimum maximum money the robber can take using state transition dynamic programmin…
Rearranging Fruits
Solve the problem of rearranging fruit baskets by comparing fruit costs and minimizing swaps using array scanning and ha…
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…
Minimum Score by Changing Two Elements
The problem asks for the minimum score after changing two elements of an array using a greedy approach.
Minimum Operations to Reduce an Integer to 0
Compute the minimum number of operations to reduce a positive integer to zero using additions or subtractions of powers …
Find the String with LCP
Determine the lexicographically smallest string matching a given LCP matrix using state transition dynamic programming.
Find the Maximum Number of Marked Indices
Maximize marked indices in an array by performing allowed operations, applying binary search to find the optimal count e…
Split With Minimum Sum
Split a positive integer into two parts to minimize their sum using a greedy approach and sorting.
Rearrange Array to Maximize Prefix Score
Maximize the number of positive prefix sums by rearranging an integer array using a greedy, order-focused strategy.
Minimum Time to Complete All Tasks
Determine the minimum active time for a computer to complete all scheduled tasks within their specific time windows effi…
Distribute Money to Maximum Children
Determine the maximum number of children who can each receive exactly 8 dollars using a greedy approach with validation …
Maximize Greatness of an Array
Maximize Greatness of an Array requires permuting numbers to exceed original values at most indices efficiently.
Smallest Missing Non-negative Integer After Operations
Find the smallest missing non-negative integer after repeated additions or subtractions of a given value in nums array e…
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…
Prime Subtraction Operation
Determine if it's possible to make the array strictly increasing using prime subtractions.
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.
Mice and Cheese
In 'Mice and Cheese', you must maximize the total reward of two mice eating cheese while respecting their preferences an…
Minimize the Maximum Difference of Pairs
Minimize the Maximum Difference of Pairs seeks to optimize the maximum pairwise difference in a set of index pairs from …
Minimum Additions to Make Valid String
Determine the minimum insertions required to transform a given string into repeated concatenations of 'abc' using dynami…
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.
Make Array Empty
Solve the "Make Array Empty" problem using binary search to determine the minimum number of operations required.
Lexicographically Smallest Beautiful String
Find the lexicographically smallest beautiful string larger than the given string using greedy choice and invariant vali…
Make Costs of Paths Equal in a Binary Tree
Minimize the cost increments required to equalize path costs in a binary tree from root to leaves.
Maximum OR
Maximize the bitwise OR of an array by applying at most k multiplication operations on selected elements.
Lexicographically Smallest Palindrome
Given a string, make it a palindrome with the fewest operations, prioritizing lexicographically smallest result.
Buy Two Chocolates
Determine the leftover money after buying exactly two chocolates using a greedy selection and sum validation approach.
Maximum Strength of a Group
Maximize the strength of a student group by carefully selecting students based on their scores, using dynamic programmin…
Minimum Cost to Make All Characters Equal
Find the minimum cost to make all characters of a binary string equal by performing two types of operations.
Lexicographically Smallest String After Substring Operation
Given a string, perform operations to make it lexicographically smaller using a greedy approach with substring modificat…
Construct the Longest New String
Maximize the length of a string built from AA, BB, and AB without creating triple repeats using DP and greedy logic.
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.
Maximum Number of Groups With Increasing Length
Maximize the number of groups that can be formed with given usage limits, leveraging binary search for optimal solutions…
Shortest String That Contains Three Strings
Find the shortest string containing three given strings using a greedy approach while ensuring it is lexicographically s…
Check if it is Possible to Split Array
Determine whether an array can be fully split into single-element subarrays using a state transition dynamic programming…
Maximum Elegance of a K-Length Subsequence
Maximize elegance of a k-length subsequence from a list of items with profits and categories.
Apply Operations to Maximize Score
Maximize the score by applying operations on a subarray at most k times, utilizing stack-based state management.
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.
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.
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 …
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…
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.
Minimum Array Length After Pair Removals
This problem involves minimizing the length of a sorted array by repeatedly removing adjacent pairs of equal elements.
Maximum Odd Binary Number
Rearrange a binary string to form the largest odd binary number using a greedy approach and least significant bit valida…
Minimum Number of Operations to Make Array Empty
Minimize the number of operations to make an array empty by leveraging array scanning and hash lookup.
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…
Minimum Processing Time
Determine the minimum total processing time by optimally assigning tasks to multiple processors using a greedy approach.
Apply Operations on Array to Maximize Sum of Squares
Maximizing the sum of squares in an array through bitwise operations on selected elements.
Longest Unequal Adjacent Groups Subsequence I
Find the longest alternating subsequence in a string array based on a binary group array.
Minimum Number of Groups to Create a Valid Assignment
The problem involves sorting balls into boxes while minimizing the number of boxes, adhering to size constraints.
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…
Maximum Spending After Buying Items
Maximize spending by carefully choosing the right items across multiple shops over m * n days.
Separate Black and White Balls
Solve the "Separate Black and White Balls" problem by swapping adjacent balls to group all black balls to the right with…
Maximum Xor Product
Find the maximum value of (a XOR x) * (b XOR x) using greedy bitwise choices and invariant validation.
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.
Remove Adjacent Almost-Equal Characters
Minimize operations to remove adjacent almost-equal characters using dynamic programming and greedy methods.
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.
Minimum Cost to Make Array Equalindromic
Determine the minimum cost to convert an integer array into a palindromic array using allowed element modifications effi…
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…
Maximum Size of a Set After Removals
Maximize a set size by strategically removing half of elements from two arrays using hash lookups and array scanning.
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.
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.
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.
Minimize OR of Remaining Elements Using Operations
Minimize the bitwise OR of the remaining elements of an array after applying at most k operations.
Maximum Palindromes After Operations
The problem focuses on maximizing the number of palindromes that can be formed from a given list of words through specif…
Earliest Second to Mark Indices II
This problem asks to determine the earliest second at which all indices in an array can be marked using a sequence of op…
Find the Maximum Sum of Node Values
Solve Find the Maximum Sum of Node Values by tracking XOR gain parity, not by simulating edge operations across the tree…
Apple Redistribution into Boxes
Distribute packs of apples into boxes using a greedy strategy, minimizing the number of boxes selected efficiently and c…
Maximize Happiness of Selected Children
Maximize the happiness of selected children by choosing the k happiest ones and applying greedy strategies to minimize l…
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…
Minimum Deletions to Make String K-Special
Minimize deletions to make a string k-special by adjusting character frequencies.
Minimum Moves to Pick K Ones
Find the minimum number of moves to pick exactly k ones from a binary array, considering a constraint on changes.
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.
Lexicographically Smallest String After Operations With Constraint
Minimize a string lexicographically using a series of operations constrained by a given integer k.
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…
Minimum Rectangles to Cover Points
Find the minimum number of rectangles needed to cover all points, given constraints on width and position.
Minimum Cost to Equalize Array
Compute the minimum cost to make all elements equal using selective operations guided by greedy choices and invariant ch…
Lexicographically Minimum String After Removing Stars
Find the lexicographically smallest string by removing stars using stack-based state management and careful character se…
Minimum Operations to Make Binary Array Elements Equal to One II
Solve the Minimum Operations to Make Binary Array Elements Equal to One II using state transition dynamic programming ef…
Maximum Points After Enemy Battles
Solve the "Maximum Points After Enemy Battles" problem by maximizing points through greedy choices with energy validatio…
Lexicographically Smallest String After a Swap
Lexicographically Smallest String After a Swap involves finding the smallest string after swapping adjacent digits with …
Minimum Cost for Cutting Cake I
In this problem, you need to minimize the cost of cutting a cake into 1x1 pieces using vertical and horizontal cuts.
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…
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.
Minimum Operations to Make Array Equal to Target
This problem requires calculating the minimum number of operations to transform one array into another using state trans…
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…
Find the Largest Palindrome Divisible by K
Compute the largest n-digit integer divisible by k that forms a palindrome using state transition dynamic programming te…
Minimum Amount of Damage Dealt to Bob
Minimize the total damage dealt to Bob using power to eliminate enemies efficiently with greedy approach.
Maximize Score of Numbers in Ranges
Maximize Score of Numbers in Ranges asks to find the maximum score by selecting integers within given intervals with a f…
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.
Minimum Number of Seconds to Make Mountain Height Zero
Determine the minimum seconds required to reduce a mountain to zero height using simultaneous workers efficiently.
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.
Find the Lexicographically Smallest Valid Sequence
Determine the lexicographically smallest valid index sequence by using state transition dynamic programming over word1 a…
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…
Smallest Divisible Digit Product II
Find the smallest zero-free number at least as large as num whose digits multiply to a product divisible by t using care…
Minimize the Maximum Adjacent Element Difference
Minimize the maximum adjacent element difference by filling missing values with two chosen numbers.
Zero Array Transformation III
Zero Array Transformation III requires removing the minimum number of queries to make all elements zero using greedy val…
Maximum Number of Distinct Elements After Operations
Maximize distinct elements in an array by performing at most one operation on each element.
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.
Maximum Coins From K Consecutive Bags
Solve the problem of maximizing coins from selecting k consecutive bags, using binary search and sliding window techniqu…
Minimum Cost to Make Arrays Identical
Minimize cost to make arrays identical by performing operations with given constraints and a greedy strategy.
Maximum Frequency After Subarray Operation
Determine the maximum frequency of a target value k after applying one subarray addition operation efficiently using arr…
Reschedule Meetings for Maximum Free Time I
Maximize free time by rescheduling up to k non-overlapping meetings within a fixed event using sliding window updates.
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…
Maximize the Minimum Game Score
Maximizing the minimum score after at most m moves, leveraging binary search and greedy strategies over an array of scor…
Eat Pizzas!
Maximize the total weight gained by optimally eating pizzas in groups of four using greedy selection and invariant valid…
Select K Disjoint Special Substrings
Determine if k non-overlapping special substrings exist in a string using dynamic programming and careful substring trac…
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.
Maximize the Distance Between Points on a Square
Select k points on a square boundary to maximize minimum Manhattan distance using binary search and greedy placement str…
Lexicographically Smallest Generated String
Generate the lexicographically smallest string by merging str1 and str2 using a greedy approach with invariant checks.
Maximum Unique Subarray Sum After Deletion
Maximize the sum of a subarray after performing deletions, ensuring elements remain unique.
Make Array Non-decreasing
Determine the maximum size of a non-decreasing array by replacing subarrays with their maximum values efficiently.
Path Existence Queries in a Graph II
Solve path existence queries in a graph using binary search on the answer space, focusing on sorted nodes and maximum di…
Minimum Operations to Convert All Elements to Zero
Calculate the fewest operations to turn all numbers in an array to zero using subarray minimum elimination strategy.
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.
Maximum Sum of Edge Values in a Graph
Maximize the sum of edge values in a connected graph by assigning unique node values and optimizing edge products.
Find Maximum Number of Non Intersecting Substrings
Determine the maximum number of non-overlapping substrings in a word, each at least four characters and matching start-e…
Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values
Select three distinct x-values from arrays to maximize the sum of their corresponding y-values efficiently using hashing…
Transform Array to All Equal Elements
Transform Array to All Equal Elements requires careful greedy choices and validating invariants to achieve uniformity ef…
Minimum Steps to Convert String with Operations
Transform word1 into word2 using minimal operations on substrings with a dynamic programming state transition approach.
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…
Find Maximum Area of a Triangle
Find the maximum area of a triangle from 2D coordinates with at least one side parallel to the x-axis or y-axis.
Maximize Spanning Tree Stability with Upgrades
Maximizing the stability of a spanning tree with upgrades requires careful optimization of edge strengths using binary s…
Minimum Stability Factor of Array
The problem requires finding the minimum stability factor of an array by utilizing binary search and math-based optimiza…
Partition Array for Maximum XOR and AND
Partition the array into three subsequences to maximize XOR and AND operations with a greedy approach.
Related Patterns
Greedy choice plus invariant validation
198 linked problems
State transition dynamic programming
51 linked problems
Array scanning plus hash lookup
40 linked problems
Binary search over the valid answer space
34 linked problems
Two-pointer scanning with invariant tracking
23 linked problems
Stack-based state management
19 linked problems