Sorting Problems
400 Sorting LeetCode problems · Browse tasks by difficulty and choose your next practice problem.
Learn the coding interview patterns behind these problems.
Start with these
15 3Sum Medium49 Group Anagrams Medium56 Merge Intervals Medium88 Merge Sorted Array Easy169 Majority Element Easy215 Kth Largest Element in an Array Medium217 Contains Duplicate Easy242 Valid Anagram Easy268 Missing Number Easy295 Find Median from Data Stream Hard347 Top K Frequent Elements Medium435 Non-overlapping Intervals Medium539 Minimum Time Difference Medium621 Task Scheduler Medium2421 Number of Good Paths Hard3273 Minimum Amount of Damage Dealt to Bob Hard3288 Length of the Longest Increasing Path Hard3301 Maximize the Total Height of Unique Towers Medium3531 Count Covered Buildings Medium
All Sorting problems
15 3Sum Medium16 3Sum Closest Medium18 4Sum Medium47 Permutations II Medium49 Group Anagrams Medium56 Merge Intervals Medium75 Sort Colors Medium88 Merge Sorted Array Easy147 Insertion Sort List Medium148 Sort List Medium164 Maximum Gap Medium169 Majority Element Easy179 Largest Number Medium215 Kth Largest Element in an Array Medium217 Contains Duplicate Easy220 Contains Duplicate III Hard229 Majority Element II Medium242 Valid Anagram Easy268 Missing Number Easy274 H-Index Medium295 Find Median from Data Stream Hard324 Wiggle Sort II Medium347 Top K Frequent Elements Medium349 Intersection of Two Arrays Easy350 Intersection of Two Arrays II Easy354 Russian Doll Envelopes Hard368 Largest Divisible Subset Medium378 Kth Smallest Element in a Sorted Matrix Medium389 Find the Difference Easy406 Queue Reconstruction by Height Medium414 Third Maximum Number Easy435 Non-overlapping Intervals Medium451 Sort Characters By Frequency Medium452 Minimum Number of Arrows to Burst Balloons Medium455 Assign Cookies Easy462 Minimum Moves to Equal Array Elements II Medium472 Concatenated Words Hard475 Heaters Medium502 IPO Hard506 Relative Ranks Easy522 Longest Uncommon Subsequence II Medium524 Longest Word in Dictionary through Deleting Medium532 K-diff Pairs in an Array Medium539 Minimum Time Difference Medium561 Array Partition Easy581 Shortest Unsorted Continuous Subarray Medium594 Longest Harmonious Subsequence Easy611 Valid Triangle Number Medium621 Task Scheduler Medium628 Maximum Product of Three Numbers Easy630 Course Schedule III Hard632 Smallest Range Covering Elements from K Lists Hard645 Set Mismatch Easy646 Maximum Length of Pair Chain Medium658 Find K Closest Elements Medium692 Top K Frequent Words Medium710 Random Pick with Blacklist Hard719 Find K-th Smallest Pair Distance Hard720 Longest Word in Dictionary Medium721 Accounts Merge Medium726 Number of Atoms Hard747 Largest Number At Least Twice of Others Easy757 Set Intersection Size At Least Two Hard767 Reorganize String Medium768 Max Chunks To Make Sorted II Hard769 Max Chunks To Make Sorted Medium786 K-th Smallest Prime Fraction Medium791 Custom Sort String Medium792 Number of Matching Subsequences Medium823 Binary Trees With Factors Medium825 Friends Of Appropriate Ages Medium826 Most Profit Assigning Work Medium833 Find And Replace in String Medium846 Hand of Straights Medium853 Car Fleet Medium857 Minimum Cost to Hire K Workers Hard869 Reordered Power of 2 Medium870 Advantage Shuffle Medium881 Boats to Save People Medium888 Fair Candy Swap Easy891 Sum of Subsequence Widths Hard893 Groups of Special-Equivalent Strings Medium899 Orderly Queue Hard905 Sort Array By Parity Easy910 Smallest Range II Medium912 Sort an Array Medium922 Sort Array By Parity II Easy923 3Sum With Multiplicity Medium937 Reorder Data in Log Files Medium939 Minimum Area Rectangle Medium945 Minimum Increment to Make Array Unique Medium948 Bag of Tokens Medium950 Reveal Cards In Increasing Order Medium954 Array of Doubled Pairs Medium969 Pancake Sorting Medium973 K Closest Points to Origin Medium975 Odd Even Jump Hard976 Largest Perimeter Triangle Easy977 Squares of a Sorted Array Easy987 Vertical Order Traversal of a Binary Tree Hard1005 Maximize Sum Of Array After K Negations Easy1029 Two City Scheduling Medium1030 Matrix Cells in Distance Order Easy1040 Moving Stones Until Consecutive II Medium1048 Longest String Chain Medium1051 Height Checker Easy1054 Distant Barcodes Medium1090 Largest Values From Labels Medium1094 Car Pooling Medium1122 Relative Sort Array Easy1169 Invalid Transactions Medium1170 Compare Strings by Frequency of the Smallest Character Medium1187 Make Array Strictly Increasing Hard1200 Minimum Absolute Difference Easy1202 Smallest String With Swaps Medium1235 Maximum Profit in Job Scheduling Hard1262 Greatest Sum Divisible by Three Medium1268 Search Suggestions System Medium1288 Remove Covered Intervals Medium1296 Divide Array in Sets of K Consecutive Numbers Medium1300 Sum of Mutated Array Closest to Target Medium1305 All Elements in Two Binary Search Trees Medium1311 Get Watched Videos by Your Friends Medium1329 Sort the Matrix Diagonally Medium1331 Rank Transform of an Array Easy1333 Filter Restaurants by Vegan-Friendly, Price and Distance Medium1337 The K Weakest Rows in a Matrix Easy1338 Reduce Array Size to The Half Medium1340 Jump Game V Hard1346 Check If N and Its Double Exist Easy1348 Tweet Counts Per Frequency Medium1353 Maximum Number of Events That Can Be Attended Medium1356 Sort Integers by The Number of 1 Bits Easy1363 Largest Multiple of Three Hard1365 How Many Numbers Are Smaller Than the Current Number Easy1366 Rank Teams by Votes Medium1383 Maximum Performance of a Team Hard1385 Find the Distance Value Between Two Arrays Easy1387 Sort Integers by The Power Value Medium1402 Reducing Dishes Hard1403 Minimum Subsequence in Non-Increasing Order Easy1418 Display Table of Food Orders in a Restaurant Medium1424 Diagonal Traverse II Medium1433 Check If a String Can Break Another String Medium1451 Rearrange Words in a Sentence Medium1460 Make Two Arrays Equal by Reversing Subarrays Easy1464 Maximum Product of Two Elements in an Array Easy1465 Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts Medium1471 The k Strongest Values in an Array Medium1478 Allocate Mailboxes Hard1481 Least Number of Unique Integers after K Removals Medium1489 Find Critical and Pseudo-Critical Edges in Minimum Spanning Tree Hard1491 Average Salary Excluding the Minimum and Maximum Salary Easy1498 Number of Subsequences That Satisfy the Given Sum Condition Medium1502 Can Make Arithmetic Progression From Sequence Easy1508 Range Sum of Sorted Subarray Sums Medium1509 Minimum Difference Between Largest and Smallest Value in Three Moves Medium1547 Minimum Cost to Cut a Stick Hard1552 Magnetic Force Between Two Balls Medium1561 Maximum Number of Coins You Can Get Medium1585 Check If String Is Transformable With Substring Sort Operations Hard1589 Maximum Sum Obtained of Any Permutation Medium1604 Alert Using Same Key-Card Three or More Times in a One Hour Period Medium1608 Special Array With X Elements Greater Than or Equal X Easy1610 Maximum Number of Visible Points Hard1619 Mean of Array After Removing Some Elements Easy1626 Best Team With No Conflicts Medium1630 Arithmetic Subarrays Medium1632 Rank Transform of a Matrix Hard1636 Sort Array by Increasing Frequency Easy1637 Widest Vertical Area Between Two Points Containing No Points Easy1647 Minimum Deletions to Make Character Frequencies Unique Medium1648 Sell Diminishing-Valued Colored Balls Medium1657 Determine if Two Strings Are Close Medium1665 Minimum Initial Energy to Finish Tasks Hard1679 Max Number of K-Sum Pairs Medium1686 Stone Game VI Medium1691 Maximum Height by Stacking Cuboids Hard1697 Checking Existence of Edge Length Limited Paths Hard1710 Maximum Units on a Truck Easy1727 Largest Submatrix With Rearrangements Medium1738 Find Kth Largest XOR Coordinate Value Medium1751 Maximum Number of Events That Can Be Attended II Hard1755 Closest Subsequence Sum Hard1782 Count Pairs Of Nodes Hard1798 Maximum Number of Consecutive Values You Can Make Medium1818 Minimum Absolute Sum Difference Medium1833 Maximum Ice Cream Bars Medium1834 Single-Threaded CPU Medium1838 Frequency of the Most Frequent Element Medium1840 Maximum Building Height Hard1846 Maximum Element After Decreasing and Rearranging Medium1847 Closest Room Hard1851 Minimum Interval to Include Each Query Hard1859 Sorting the Sentence Easy1877 Minimize Maximum Pair Sum in Array Medium1878 Get Biggest Three Rhombus Sums in a Grid Medium1887 Reduction Operations to Make the Array Elements Equal Medium1889 Minimum Space Wasted From Packaging Hard1913 Maximum Product Difference Between Two Pairs Easy1921 Eliminate Maximum Number of Monsters Medium1943 Describe the Painting Medium1968 Array With Elements Not Equal to Average of Neighbors Medium1984 Minimum Difference Between Highest and Lowest of K Scores Easy1985 Find the Kth Largest Integer in the Array Medium1996 The Number of Weak Characters in the Game Medium1998 GCD Sort of an Array Hard2007 Find Original Array From Doubled Array Medium2008 Maximum Earnings From Taxi Medium2033 Minimum Operations to Make a Uni-Value Grid Medium2037 Minimum Number of Moves to Seat Everyone Easy2054 Two Best Non-Overlapping Events Medium2070 Most Beautiful Item for Each Query Medium2071 Maximum Number of Tasks You Can Assign Hard2089 Find Target Indices After Sorting Array Easy2092 Find All People With Secret Hard2094 Finding 3-Digit Even Numbers Easy2099 Find Subsequence of Length K With the Largest Sum Easy2122 Recover the Original Array Hard2126 Destroying Asteroids Medium2135 Count Words Obtained After Adding a Letter Medium2136 Earliest Possible Day of Full Bloom Hard2141 Maximum Running Time of N Computers Hard2144 Minimum Cost of Buying Candies With Discount Easy2146 K Highest Ranked Items Within a Price Range Medium2148 Count Elements With Strictly Smaller and Greater Elements Easy2154 Keep Multiplying Found Values by Two Easy2160 Minimum Sum of Four Digit Number After Splitting Digits Easy2164 Sort Even and Odd Indices Independently Easy2165 Smallest Value of the Rearranged Number Medium2171 Removing Minimum Number of Magic Beans Medium2191 Sort the Jumbled Numbers Medium2195 Append K Integers With Minimal Sum Medium2225 Find Players With Zero or One Losses Medium2231 Largest Number After Digit Swaps by Parity Easy2234 Maximum Total Beauty of the Gardens Hard2242 Maximum Score of a Node Sequence Hard2248 Intersection of Multiple Arrays Easy2250 Count Number of Rectangles Containing Each Point Medium2251 Number of Flowers in Full Bloom Hard2271 Maximum White Tiles Covered by a Carpet Medium2273 Find Resultant Array After Removing Anagrams Easy2274 Maximum Consecutive Floors Without Special Floors Medium2279 Maximum Bags With Full Capacity of Rocks Medium2280 Minimum Lines to Represent a Line Chart Medium2285 Maximum Total Importance of Roads Medium2294 Partition Array Such That Maximum Difference Is K Medium2300 Successful Pairs of Spells and Potions Medium2332 The Latest Time to Catch a Bus Medium2333 Minimum Sum of Squared Difference Medium2335 Minimum Amount of Time to Fill Cups Easy2342 Max Sum of a Pair With Equal Sum of Digits Medium2343 Query Kth Smallest Trimmed Number Medium2344 Minimum Deletions to Make Array Divisible Hard2357 Make Array Zero by Subtracting Equal Amounts Easy2363 Merge Similar Items Easy2386 Find the K-Sum of an Array Hard2389 Longest Subsequence With Limited Sum Easy2402 Meeting Rooms III Hard2406 Divide Intervals Into Minimum Number of Groups Medium2410 Maximum Matching of Players With Trainers Medium2412 Minimum Money Required Before Transactions Hard2418 Sort the People Easy2421 Number of Good Paths Hard2441 Largest Positive Integer That Exists With Its Negative Easy2448 Minimum Cost to Make Array Equal Hard2449 Minimum Number of Operations to Make Arrays Similar Hard2454 Next Greater Element IV Hard2456 Most Popular Video Creator Medium2463 Minimum Total Distance Traveled Hard2465 Number of Distinct Averages Easy2475 Number of Unequal Triplets in Array Easy2491 Divide Players Into Teams of Equal Skill Medium2497 Maximum Star Sum of a Graph Medium2500 Delete Greatest Value in Each Row Easy2501 Longest Square Streak in an Array Medium2503 Maximum Number of Points From Grid Queries Hard2512 Reward Top K Students Medium2517 Maximum Tastiness of Candy Basket Medium2542 Maximum Subsequence Score Medium2545 Sort the Students by Their Kth Score Medium2551 Put Marbles in Bags Hard2554 Maximum Number of Integers to Choose From a Range I Medium2563 Count the Number of Fair Pairs Medium2567 Minimum Score by Changing Two Elements Medium2576 Find the Maximum Number of Marked Indices Medium2578 Split With Minimum Sum Easy2580 Count Ways to Group Overlapping Ranges Medium2583 Kth Largest Sum in a Binary Tree Medium2587 Rearrange Array to Maximize Prefix Score Medium2589 Minimum Time to Complete All Tasks Hard2592 Maximize Greatness of an Array Medium2593 Find Score of an Array After Marking All Elements Medium2597 The Number of Beautiful Subsets Medium2602 Minimum Operations to Make All Array Elements Equal Medium2607 Make K-Subarray Sums Equal Medium2611 Mice and Cheese Medium2616 Minimize the Maximum Difference of Pairs Medium2659 Make Array Empty Hard2679 Sum in a Matrix Medium2681 Power of Heroes Hard2706 Buy Two Chocolates Easy2708 Maximum Strength of a Group Medium2713 Maximum Strictly Increasing Cells in a Matrix Hard2731 Movement of Robots Medium2733 Neither Minimum nor Maximum Easy2736 Maximum Sum Queries Hard2740 Find the Value of the Partition Medium2747 Count Zero Request Servers Medium2751 Robot Collisions Hard2766 Relocate Marbles Medium2779 Maximum Beauty of an Array After Applying Operation Medium2780 Minimum Index of a Valid Split Medium2784 Check if Array is Good Easy2785 Sort Vowels in a String Medium2790 Maximum Number of Groups With Increasing Length Hard2809 Minimum Time to Make Array Sum At Most x Hard2813 Maximum Elegance of a K-Length Subsequence Hard2818 Apply Operations to Maximize Score Hard2824 Count Pairs Whose Sum is Less than Target Easy2830 Maximize the Profit as the Salesman Medium2840 Check if Strings Can be Made Equal With Operations II Medium2860 Happy Students Medium2895 Minimum Processing Time Medium2931 Maximum Spending After Buying Items Hard2933 High-Access Employees Medium2943 Maximize Area of Square Hole in Grid Medium2948 Make Lexicographically Smallest Array by Swapping Elements Medium2952 Minimum Number of Coins to be Added Medium2966 Divide Array Into Arrays With Max Difference Medium2967 Minimum Cost to Make Array Equalindromic Medium2968 Apply Operations to Maximize Frequency Score Hard2971 Find Polygon With the Largest Perimeter Medium2973 Find Number of Coins to Place in Tree Nodes Hard2974 Minimum Number Game Easy2996 Smallest Missing Integer Greater Than Sequential Prefix Sum Easy3010 Divide an Array Into Subarrays With Minimum Cost I Easy3011 Find if Array Can Be Sorted Medium3016 Minimum Number of Pushes to Type Word II Medium3024 Type of Triangle Easy3025 Find the Number of Ways to Place People I Medium3027 Find the Number of Ways to Place People II Hard3035 Maximum Palindromes After Operations Medium3039 Apply Operations to Make String Empty Medium3041 Maximize Consecutive Elements in an Array After Modification Hard3068 Find the Maximum Sum of Node Values Hard3074 Apple Redistribution into Boxes Easy3075 Maximize Happiness of Selected Children Medium3080 Mark Elements on Array by Performing Queries Medium3081 Replace Question Marks in String to Minimize Its Value Medium3085 Minimum Deletions to Make String K-Special Medium3098 Find the Sum of Subsequence Powers Hard3102 Minimize Manhattan Distances Hard3107 Minimum Operations to Make Median of Array Equal to K Medium3111 Minimum Rectangles to Cover Points Medium3132 Find the Integer Added to Array II Medium3143 Maximum Points Inside the Square Medium3169 Count Days Without Meetings Medium3186 Maximum Total Damage With Spell Casting Medium3194 Minimum Average of Smallest and Largest Elements Easy3218 Minimum Cost for Cutting Cake I Medium3219 Minimum Cost for Cutting Cake II Hard3265 Count Almost Equal Pairs I Medium3267 Count Almost Equal Pairs II Hard3273 Minimum Amount of Damage Dealt to Bob Hard3281 Maximize Score of Numbers in Ranges Medium3288 Length of the Longest Increasing Path Hard3301 Maximize the Total Height of Unique Towers Medium3319 K-th Largest Perfect Subtree Size in Binary Tree Medium3346 Maximum Frequency of an Element After Performing Operations I Medium3347 Maximum Frequency of an Element After Performing Operations II Hard3362 Zero Array Transformation III Medium3365 Rearrange K Substrings to Form Target String Medium3380 Maximum Area Rectangle With Point Constraints I Medium3382 Maximum Area Rectangle With Point Constraints II Hard3394 Check if Grid can be Cut into Sections Medium3397 Maximum Number of Distinct Elements After Operations Medium3413 Maximum Coins From K Consecutive Bags Medium3414 Maximum Score of Non-overlapping Intervals Hard3424 Minimum Cost to Make Arrays Identical Medium3428 Maximum and Minimum Sums of at Most Size K Subsequences Medium3433 Count Mentions Per User Medium3446 Sort Matrix by Diagonals Medium3457 Eat Pizzas! Medium3458 Select K Disjoint Special Substrings Medium3462 Maximum Sum With at Most K Elements Medium3467 Transform Array by Parity Easy3478 Choose K Elements With Maximum Sum Medium3517 Smallest Palindromic Rearrangement I Medium3531 Count Covered Buildings Medium3534 Path Existence Queries in a Graph II Hard3536 Maximum Product of Two Digits Easy3545 Minimum Deletions for At Most K Distinct Characters Easy3547 Maximum Sum of Edge Values in a Graph Hard3551 Minimum Swaps to Sort by Digit Sum Medium3556 Sum of Largest Prime Substrings Medium3567 Minimum Absolute Difference in Sliding Submatrix Medium3572 Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values Medium3606 Coupon Code Validator Easy3608 Minimum Time for K Connected Components Medium