Greedy
121 problems · 79 with full explanations
14 Easy43 Medium17 Hard
Greedy algorithms make locally optimal choices at each step, hoping to reach a global optimum. Greedy works when a problem has the "greedy choice property" and "optimal substructure". Common applications: interval scheduling, activity selection, Huffman coding, and jump game.
How to practice
To practice Greedy problems effectively, start with the Easy problems listed below, trace through each solution on paper, then re-implement without looking. When you can recognise the greedy pattern within 30 seconds of reading a new problem, move on to Medium difficulty. Use the related topic pages and our study guide for a structured progression.
Start here (Easy + explained)
All Greedy problems
- 11.Container With Most WaterMedium
- 44.Wildcard MatchingHard
- 122.Best Time to Buy and Sell Stock IIMedium
- 135.CandyHard
- 179.Largest NumberMedium
- 316.Remove Duplicate LettersMedium
- 321.Create Maximum NumberUnknown
- 330.Patching ArrayHard
- 502.IPOUnknown
- 605.Can Place FlowersEasy
- 624.Maximum Distance in ArraysUnknown
- 632.Smallest Range Covering Elements from K ListsHard
- 670.Maximum SwapMedium
- 678.Valid Parenthesis StringMedium
- 757.Set Intersection Size At Least TwoUnknown
- 763.Partition LabelsMedium
- 769.Max Chunks To Make SortedMedium
- 781.Rabbits in ForestMedium
- 807.Max Increase to Keep City SkylineMedium
- 826.Most Profit Assigning WorkMedium
- 857.Minimum Cost to Hire K WorkersHard
- 860.Lemonade ChangeEasy
- 921.Minimum Add to Make Parentheses ValidMedium
- 944.Delete Columns to Make SortedEasy
- 955.Delete Columns to Make Sorted IIMedium
- 976.Largest Perimeter TriangleMedium
- 995.Minimum Number of K Consecutive Bit FlipsUnknown
- 1007.Minimum Domino Rotations For Equal RowMedium
- 1081.Smallest Subsequence of Distinct CharactersMedium
- 1323.Maximum 69 NumberEasy
- 1353.Maximum Number of Events That Can Be AttendedMedium
- 1400.Construct K Palindrome StringsUnknown
- 1405.Longest Happy StringUnknown
- 1432.Max Difference You Can Get From Changing an IntegerUnknown
- 1465.Maximum Area of a Piece of Cake After Horizontal and Vertical CutsUnknown
- 1488.Avoid Flood in The CityUnknown
- 1509.Minimum Difference Between Largest and Smallest Value in Three MovesMedium
- 1526.Minimum Number of Increments on Subarrays to Form a Target ArrayUnknown
- 1529.Minimum Suffix FlipsUnknown
- 1536.Minimum Swaps to Arrange a Binary GridUnknown
- 1578.Minimum Time to Make Rope ColorfulMedium
- 1605.Find Valid Matrix Given Row and Column SumsUnknown
- 1653.Minimum Deletions to Make String BalancedMedium
- 1671.Minimum Number of Removals to Make Mountain ArrayHard
- 1689.Partitioning Into Minimum Number Of Deci-Binary NumbersMedium
- 1717.Maximum Score From Removing SubstringsUnknown
- 1727.Largest Submatrix With RearrangementsUnknown
- 1733.Minimum Number of People to TeachUnknown
- 1758.Minimum Changes To Make Alternating Binary StringUnknown
- 1792.Maximum Average Pass RatioMedium
- 1802.Maximum Value at a Given Index in a Bounded ArrayHard
- 1877.Minimize Maximum Pair Sum in ArrayEasy
- 1878.Get Biggest Three Rhombus Sums in a GridUnknown
- 1888.Minimum Number of Flips to Make the Binary String AlternatingUnknown
- 1911.Maximum Alternating Subsequence SumUnknown
- 1957.Delete Characters to Make Fancy StringUnknown
- 1963.Minimum Number of Swaps to Make the String BalancedUnknown
- 1975.Maximum Matrix SumUnknown
- 2014.Longest Subsequence Repeated k TimesUnknown
- 2033.Minimum Operations to Make a Uni-Value GridUnknown
- 2071.Maximum Number of Tasks You Can AssignUnknown
- 2091.Removing Minimum and Maximum From ArrayMedium
- 2116.Check if a Parentheses String Can Be ValidMedium
- 2131.Longest Palindrome by Concatenating Two Letter WordsMedium
- 2134.Minimum Swaps to Group All 1's Together IIMedium
- 2141.Maximum Running Time of N ComputersUnknown
- 2182.Construct String With Repeat LimitMedium
- 2285.Maximum Total Importance of RoadsHard
- 2294.Partition Array Such That Maximum Difference Is KHard
- 2311.Longest Binary Subsequence Less Than or Equal to KMedium
- 2375.Construct Smallest Number From DI StringMedium
- 2389.Longest Subsequence With Limited SumEasy
- 2402.Meeting Rooms IIIHard
- 2406.Divide Intervals Into Minimum Number of GroupsMedium
- 2410.Maximum Matching of Players With TrainersMedium
- 2429.Minimize XORHard
- 2434.Using a Robot to Print the Lexicographically Smallest StringMedium
- 2491.Divide Players Into Teams of Equal SkillMedium
- 2528.Maximize the Minimum Powered CityHard
- 2530.Maximal Score After Applying K OperationsMedium
- 2551.Put Marbles in BagsHard
- 2554.Maximum Number of Integers to Choose From a Range IMedium
- 2558.Take Gifts From the Richest PileEasy
- 2561.Rearranging FruitsHard
- 2566.Maximum Difference by Remapping a DigitEasy
- 2593.Find Score of an Array After Marking All ElementsMedium
- 2598.Smallest Missing Non-negative Integer After OperationsUnknown
- 2601.Prime Subtraction OperationHard
- 2616.Minimize the Maximum Difference of PairsHard
- 2645.Minimum Additions to Make Valid StringMedium
- 2818.Apply Operations to Maximize ScoreUnknown
- 2900.Longest Unequal Adjacent Groups Subsequence IEasy
- 2901.Longest Unequal Adjacent Groups Subsequence IIUnknown
- 2914.Minimum Number of Changes to Make Binary String BeautifulEasy
- 2918.Minimum Equal Sum of Two Arrays After Replacing ZerosUnknown
- 2938.Separate Black and White BallsMedium
- 2948.Make Lexicographically Smallest Array by Swapping ElementsUnknown
- 2966.Divide Array Into Arrays With Max DifferenceMedium
- 3016.Minimum Number of Pushes to Type Word IIMedium
- 3066.Minimum Operations to Exceed Threshold Value IIMedium
- 3068.Find the Maximum Sum of Node ValuesHard
- 3074.Apple Redistribution into BoxesUnknown
- 3085.Minimum Deletions to Make String K-SpecialEasy
- 3170.Lexicographically Minimum String After Removing StarsUnknown
- 3191.Minimum Operations to Make Binary Array Elements Equal to One IMedium
- 3192.Minimum Operations to Make Binary Array Elements Equal to One IIEasy
- 3228.Maximum Number of Operations to Move Ones to the EndUnknown
- 3296.Minimum Number of Seconds to Make Mountain Height ZeroMedium
- 3362.Zero Array Transformation IIIUnknown
- 3394.Check if Grid can be Cut into SectionsUnknown
- 3397.Maximum Number of Distinct Elements After OperationsUnknown
- 3439.Reschedule Meetings for Maximum Free Time IEasy
- 3440.Reschedule Meetings for Maximum Free Time IIUnknown
- 3443.Maximum Manhattan Distance After K ChangesUnknown
- 3474.Lexicographically Smallest Generated StringEasy
- 3542.Minimum Operations to Convert All Elements to ZeroUnknown
- 3546.Equal Sum Grid Partition IUnknown
- 3548.Equal Sum Grid Partition IIUnknown
- 3562.Maximum Profit from Trading Stocks with DiscountsUnknown
- 3634.Minimum Removals to Balance ArrayUnknown
- 3661.Maximum Walls Destroyed by RobotsUnknown