Skip to content
Use code for 50% offSee plans

Greedy Problems

377 Greedy LeetCode problems · Solve with AI-powered hints & step-by-step explanations.

Learn the coding interview patterns behind these problems.

Start with these

All Greedy problems

11 Container With Most Water Medium44 Wildcard Matching Hard45 Jump Game II Medium55 Jump Game Medium122 Best Time to Buy and Sell Stock II Medium134 Gas Station Medium135 Candy Hard179 Largest Number Medium316 Remove Duplicate Letters Medium321 Create Maximum Number Hard324 Wiggle Sort II Medium330 Patching Array Hard334 Increasing Triplet Subsequence Medium376 Wiggle Subsequence Medium397 Integer Replacement Medium402 Remove K Digits Medium409 Longest Palindrome Easy410 Split Array Largest Sum Hard420 Strong Password Checker Hard435 Non-overlapping Intervals Medium452 Minimum Number of Arrows to Burst Balloons Medium455 Assign Cookies Easy502 IPO Hard517 Super Washing Machines Hard561 Array Partition Easy581 Shortest Unsorted Continuous Subarray Medium605 Can Place Flowers Easy611 Valid Triangle Number Medium621 Task Scheduler Medium624 Maximum Distance in Arrays Medium630 Course Schedule III Hard632 Smallest Range Covering Elements from K Lists Hard646 Maximum Length of Pair Chain Medium649 Dota2 Senate Medium659 Split Array into Consecutive Subsequences Medium670 Maximum Swap Medium678 Valid Parenthesis String Medium680 Valid Palindrome II Easy714 Best Time to Buy and Sell Stock with Transaction Fee Medium738 Monotone Increasing Digits Medium757 Set Intersection Size At Least Two Hard763 Partition Labels Medium765 Couples Holding Hands Hard767 Reorganize String Medium768 Max Chunks To Make Sorted II Hard769 Max Chunks To Make Sorted Medium781 Rabbits in Forest Medium807 Max Increase to Keep City Skyline Medium826 Most Profit Assigning Work Medium846 Hand of Straights Medium857 Minimum Cost to Hire K Workers Hard860 Lemonade Change Easy861 Score After Flipping Matrix Medium870 Advantage Shuffle Medium871 Minimum Number of Refueling Stops Hard881 Boats to Save People Medium910 Smallest Range II Medium921 Minimum Add to Make Parentheses Valid Medium936 Stamping The Sequence Hard942 DI String Match Easy945 Minimum Increment to Make Array Unique Medium948 Bag of Tokens Medium954 Array of Doubled Pairs Medium955 Delete Columns to Make Sorted II Medium969 Pancake Sorting Medium976 Largest Perimeter Triangle Easy984 String Without AAA or BBB Medium991 Broken Calculator Medium1005 Maximize Sum Of Array After K Negations Easy1007 Minimum Domino Rotations For Equal Row Medium1013 Partition Array Into Three Parts With Equal Sum Easy1024 Video Stitching Medium1029 Two City Scheduling Medium1053 Previous Permutation With One Swap Medium1054 Distant Barcodes Medium1081 Smallest Subsequence of Distinct Characters Medium1090 Largest Values From Labels Medium1130 Minimum Cost Tree From Leaf Values Medium1144 Decrease Elements To Make Array Zigzag Medium1147 Longest Chunked Palindrome Decomposition Hard1217 Minimum Cost to Move Chips to The Same Position Easy1221 Split a String in Balanced Strings Easy1247 Minimum Swaps to Make Strings Equal Medium1253 Reconstruct a 2-Row Binary Matrix Medium1262 Greatest Sum Divisible by Three Medium1282 Group the People Given the Group Size They Belong To Medium1296 Divide Array in Sets of K Consecutive Numbers Medium1323 Maximum 69 Number Easy1326 Minimum Number of Taps to Open to Water a Garden Hard1328 Break a Palindrome Medium1330 Reverse Subarray To Maximize Array Value Hard1338 Reduce Array Size to The Half Medium1353 Maximum Number of Events That Can Be Attended Medium1363 Largest Multiple of Three Hard1382 Balance a Binary Search Tree Medium1383 Maximum Performance of a Team Hard1386 Cinema Seat Allocation Medium1388 Pizza With 3n Slices Hard1400 Construct K Palindrome Strings Medium1402 Reducing Dishes Hard1403 Minimum Subsequence in Non-Increasing Order Easy1405 Longest Happy String Medium1414 Find the Minimum Number of Fibonacci Numbers Whose Sum Is K Medium1432 Max Difference You Can Get From Changing an Integer Medium1433 Check If a String Can Break Another String Medium1465 Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts Medium1481 Least Number of Unique Integers after K Removals Medium1488 Avoid Flood in The City Medium1505 Minimum Possible Integer After at Most K Adjacent Swaps On Digits Hard1509 Minimum Difference Between Largest and Smallest Value in Three Moves Medium1520 Maximum Number of Non-Overlapping Substrings Hard1526 Minimum Number of Increments on Subarrays to Form a Target Array Hard1529 Minimum Suffix Flips Medium1536 Minimum Swaps to Arrange a Binary Grid Medium1537 Get the Maximum Score Hard1541 Minimum Insertions to Balance a Parentheses String Medium1546 Maximum Number of Non-Overlapping Subarrays With Sum Equals Target Medium1558 Minimum Numbers of Function Calls to Make Target Array Medium1561 Maximum Number of Coins You Can Get Medium1567 Maximum Length of Subarray With Positive Product Medium1578 Minimum Time to Make Rope Colorful Medium1585 Check If String Is Transformable With Substring Sort Operations Hard1589 Maximum Sum Obtained of Any Permutation Medium1605 Find Valid Matrix Given Row and Column Sums Medium1606 Find Servers That Handled Most Number of Requests Hard1642 Furthest Building You Can Reach Medium1647 Minimum Deletions to Make Character Frequencies Unique Medium1648 Sell Diminishing-Valued Colored Balls Medium1663 Smallest String With A Given Numeric Value Medium1665 Minimum Initial Energy to Finish Tasks Hard1671 Minimum Number of Removals to Make Mountain Array Hard1673 Find the Most Competitive Subsequence Medium1675 Minimize Deviation in Array Hard1686 Stone Game VI Medium1689 Partitioning Into Minimum Number Of Deci-Binary Numbers Medium1702 Maximum Binary String After Change Medium1703 Minimum Adjacent Swaps for K Consecutive Ones Hard1705 Maximum Number of Eaten Apples Medium1710 Maximum Units on a Truck Easy1713 Minimum Operations to Make a Subsequence Hard1717 Maximum Score From Removing Substrings Medium1727 Largest Submatrix With Rearrangements Medium1733 Minimum Number of People to Teach Medium1736 Latest Time by Replacing Hidden Digits Easy1739 Building Boxes Hard1753 Maximum Score From Removing Stones Medium1754 Largest Merge Of Two Strings Medium1764 Form Array by Concatenating Subarrays of Another Array Medium1775 Equal Sum Arrays With Minimum Number of Operations Medium1785 Minimum Elements to Add to Form a Given Sum Medium1792 Maximum Average Pass Ratio Medium1798 Maximum Number of Consecutive Values You Can Make Medium1802 Maximum Value at a Given Index in a Bounded Array Medium1824 Minimum Sideway Jumps Medium1827 Minimum Operations to Make the Array Increasing Easy1833 Maximum Ice Cream Bars Medium1838 Frequency of the Most Frequent Element Medium1846 Maximum Element After Decreasing and Rearranging Medium1850 Minimum Adjacent Swaps to Reach the Kth Smallest Number Medium1864 Minimum Number of Swaps to Make the Binary String Alternating Medium1877 Minimize Maximum Pair Sum in Array Medium1881 Maximum Value after Insertion Medium1899 Merge Triplets to Form Target Triplet Medium1903 Largest Odd Number in String Easy1921 Eliminate Maximum Number of Monsters Medium1927 Sum Game Medium1936 Add Minimum Number of Rungs Medium1946 Largest Number After Mutating Substring Medium1953 Maximum Number of Weeks for Which You Can Work Medium1962 Remove Stones to Minimize the Total Medium1963 Minimum Number of Swaps to Make the String Balanced Medium1968 Array With Elements Not Equal to Average of Neighbors Medium1969 Minimum Non-Zero Product of the Array Elements Medium1974 Minimum Time to Type Word Using Special Typewriter Easy1975 Maximum Matrix Sum Medium1996 The Number of Weak Characters in the Game Medium2007 Find Original Array From Doubled Array Medium2014 Longest Subsequence Repeated k Times Hard2027 Minimum Moves to Convert String Easy2029 Stone Game IX Medium2030 Smallest K-Length Subsequence With Occurrences of a Letter Hard2037 Minimum Number of Moves to Seat Everyone Easy2038 Remove Colored Pieces if Both Neighbors are the Same Color Medium2064 Minimized Maximum of Products Distributed to Any Store Medium2071 Maximum Number of Tasks You Can Assign Hard2078 Two Furthest Houses With Different Colors Easy2086 Minimum Number of Food Buckets to Feed the Hamsters Medium2087 Minimum Cost Homecoming of a Robot in a Grid Medium2091 Removing Minimum and Maximum From Array Medium2116 Check if a Parentheses String Can Be Valid Medium2126 Destroying Asteroids Medium2131 Longest Palindrome by Concatenating Two Letter Words Medium2132 Stamping the Grid Hard2136 Earliest Possible Day of Full Bloom Hard2139 Minimum Moves to Reach Target Score Medium2141 Maximum Running Time of N Computers Hard2144 Minimum Cost of Buying Candies With Discount Easy2160 Minimum Sum of Four Digit Number After Splitting Digits Easy2170 Minimum Operations to Make the Array Alternating Medium2171 Removing Minimum Number of Magic Beans Medium2178 Maximum Split of Positive Even Integers Medium2182 Construct String With Repeat Limit Medium2193 Minimum Number of Moves to Make Palindrome Hard2195 Append K Integers With Minimal Sum Medium2202 Maximize the Topmost Element After K Moves Medium2207 Maximize Number of Subsequences in a String Medium2208 Minimum Operations to Halve Array Sum Medium2216 Minimum Deletions to Make Array Beautiful Medium2224 Minimum Number of Operations to Convert Time Easy2233 Maximum Product After K Increments Medium2234 Maximum Total Beauty of the Gardens Hard2241 Design an ATM Machine Medium2244 Minimum Rounds to Complete All Tasks Medium2259 Remove Digit From Number to Maximize Result Easy2271 Maximum White Tiles Covered by a Carpet Medium2279 Maximum Bags With Full Capacity of Rocks Medium2285 Maximum Total Importance of Roads Medium2294 Partition Array Such That Maximum Difference Is K Medium2310 Sum of Numbers With Units Digit K Medium2311 Longest Binary Subsequence Less Than or Equal to K Medium2333 Minimum Sum of Squared Difference Medium2335 Minimum Amount of Time to Fill Cups Easy2350 Shortest Impossible Sequence of Rolls Hard2357 Make Array Zero by Subtracting Equal Amounts Easy2358 Maximum Number of Groups Entering a Competition Medium2366 Minimum Replacements to Sort the Array Hard2375 Construct Smallest Number From DI String Medium2383 Minimum Hours of Training to Win a Competition Easy2384 Largest Palindromic Number Medium2389 Longest Subsequence With Limited Sum Easy2405 Optimal Partition of String Medium2406 Divide Intervals Into Minimum Number of Groups Medium2410 Maximum Matching of Players With Trainers Medium2412 Minimum Money Required Before Transactions Hard2429 Minimize XOR Medium2434 Using a Robot to Print the Lexicographically Smallest String Medium2439 Minimize Maximum of Array Medium2448 Minimum Cost to Make Array Equal Hard2449 Minimum Number of Operations to Make Arrays Similar Hard2457 Minimum Addition to Make Integer Beautiful Medium2472 Maximum Number of Non-overlapping Palindrome Substrings Hard2486 Append Characters to String to Make Subsequence Medium2497 Maximum Star Sum of a Graph Medium2498 Frog Jump II Medium2499 Minimum Total Cost to Make Arrays Unequal Hard2517 Maximum Tastiness of Candy Basket Medium2522 Partition String Into Substrings With Values at Most K Medium2528 Maximize the Minimum Powered City Hard2530 Maximal Score After Applying K Operations Medium2541 Minimum Operations to Make Array Equal II Medium2542 Maximum Subsequence Score Medium2551 Put Marbles in Bags Hard2554 Maximum Number of Integers to Choose From a Range I Medium2560 House Robber IV Medium2561 Rearranging Fruits Hard2566 Maximum Difference by Remapping a Digit Easy2567 Minimum Score by Changing Two Elements Medium2571 Minimum Operations to Reduce an Integer to 0 Medium2573 Find the String with LCP Hard2576 Find the Maximum Number of Marked Indices Medium2578 Split With Minimum Sum Easy2587 Rearrange Array to Maximize Prefix Score Medium2589 Minimum Time to Complete All Tasks Hard2591 Distribute Money to Maximum Children Easy2592 Maximize Greatness of an Array Medium2598 Smallest Missing Non-negative Integer After Operations Medium2600 K Items With the Maximum Sum Easy2601 Prime Subtraction Operation Medium2607 Make K-Subarray Sums Equal Medium2611 Mice and Cheese Medium2616 Minimize the Maximum Difference of Pairs Medium2645 Minimum Additions to Make Valid String Medium2656 Maximum Sum With Exactly K Elements Easy2659 Make Array Empty Hard2663 Lexicographically Smallest Beautiful String Hard2673 Make Costs of Paths Equal in a Binary Tree Medium2680 Maximum OR Medium2697 Lexicographically Smallest Palindrome Easy2706 Buy Two Chocolates Easy2708 Maximum Strength of a Group Medium2712 Minimum Cost to Make All Characters Equal Medium2734 Lexicographically Smallest String After Substring Operation Medium2745 Construct the Longest New String Medium2789 Largest Element in an Array after Merge Operations Medium2790 Maximum Number of Groups With Increasing Length Hard2800 Shortest String That Contains Three Strings Medium2811 Check if it is Possible to Split Array Medium2813 Maximum Elegance of a K-Length Subsequence Hard2818 Apply Operations to Maximize Score Hard2829 Determine the Minimum Sum of a k-avoiding Array Medium2834 Find the Minimum Possible Sum of a Beautiful Array Medium2835 Minimum Operations to Form Subsequence With Target Sum Hard2842 Count K-Subsequences of a String With Maximum Beauty Hard2844 Minimum Operations to Make a Special Number Medium2856 Minimum Array Length After Pair Removals Medium2864 Maximum Odd Binary Number Easy2870 Minimum Number of Operations to Make Array Empty Medium2871 Split Array Into Maximum Number of Subarrays Medium2895 Minimum Processing Time Medium2897 Apply Operations on Array to Maximize Sum of Squares Hard2900 Longest Unequal Adjacent Groups Subsequence I Easy2910 Minimum Number of Groups to Create a Valid Assignment Medium2918 Minimum Equal Sum of Two Arrays After Replacing Zeros Medium2931 Maximum Spending After Buying Items Hard2938 Separate Black and White Balls Medium2939 Maximum Xor Product Medium2952 Minimum Number of Coins to be Added Medium2957 Remove Adjacent Almost-Equal Characters Medium2966 Divide Array Into Arrays With Max Difference Medium2967 Minimum Cost to Make Array Equalindromic Medium2971 Find Polygon With the Largest Perimeter Medium3002 Maximum Size of a Set After Removals Medium3012 Minimize Length of Array Using Operations Medium3014 Minimum Number of Pushes to Type Word I Easy3016 Minimum Number of Pushes to Type Word II Medium3022 Minimize OR of Remaining Elements Using Operations Hard3035 Maximum Palindromes After Operations Medium3049 Earliest Second to Mark Indices II Hard3068 Find the Maximum Sum of Node Values Hard3074 Apple Redistribution into Boxes Easy3075 Maximize Happiness of Selected Children Medium3081 Replace Question Marks in String to Minimize Its Value Medium3085 Minimum Deletions to Make String K-Special Medium3086 Minimum Moves to Pick K Ones Hard3091 Apply Operations to Make Sum of Array Greater Than or Equal to k Medium3106 Lexicographically Smallest String After Operations With Constraint Medium3107 Minimum Operations to Make Median of Array Equal to K Medium3111 Minimum Rectangles to Cover Points Medium3139 Minimum Cost to Equalize Array Hard3170 Lexicographically Minimum String After Removing Stars Medium3192 Minimum Operations to Make Binary Array Elements Equal to One II Medium3207 Maximum Points After Enemy Battles Medium3216 Lexicographically Smallest String After a Swap Easy3218 Minimum Cost for Cutting Cake I Medium3219 Minimum Cost for Cutting Cake II Hard3228 Maximum Number of Operations to Move Ones to the End Medium3229 Minimum Operations to Make Array Equal to Target Hard3244 Shortest Distance After Road Addition Queries II Hard3260 Find the Largest Palindrome Divisible by K Hard3273 Minimum Amount of Damage Dealt to Bob Hard3281 Maximize Score of Numbers in Ranges Medium3282 Reach End of Array With Max Score Medium3296 Minimum Number of Seconds to Make Mountain Height Zero Medium3301 Maximize the Total Height of Unique Towers Medium3302 Find the Lexicographically Smallest Valid Sequence Medium3326 Minimum Division Operations to Make Array Non Decreasing Medium3348 Smallest Divisible Digit Product II Hard3357 Minimize the Maximum Adjacent Element Difference Hard3362 Zero Array Transformation III Medium3397 Maximum Number of Distinct Elements After Operations Medium3402 Minimum Operations to Make Columns Strictly Increasing Easy3413 Maximum Coins From K Consecutive Bags Medium3424 Minimum Cost to Make Arrays Identical Medium3434 Maximum Frequency After Subarray Operation Medium3439 Reschedule Meetings for Maximum Free Time I Medium3440 Reschedule Meetings for Maximum Free Time II Medium3449 Maximize the Minimum Game Score Hard3457 Eat Pizzas! Medium3458 Select K Disjoint Special Substrings Medium3462 Maximum Sum With at Most K Elements Medium3464 Maximize the Distance Between Points on a Square Hard3474 Lexicographically Smallest Generated String Hard3487 Maximum Unique Subarray Sum After Deletion Easy3523 Make Array Non-decreasing Medium3534 Path Existence Queries in a Graph II Hard3542 Minimum Operations to Convert All Elements to Zero Medium3545 Minimum Deletions for At Most K Distinct Characters Easy3547 Maximum Sum of Edge Values in a Graph Hard3557 Find Maximum Number of Non Intersecting Substrings Medium3572 Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values Medium3576 Transform Array to All Equal Elements Medium3579 Minimum Steps to Convert String with Operations Hard3587 Minimum Adjacent Swaps to Alternate Parity Medium3588 Find Maximum Area of a Triangle Medium3600 Maximize Spanning Tree Stability with Upgrades Hard3605 Minimum Stability Factor of Array Hard3630 Partition Array for Maximum XOR and AND Hard