Sorting
103 problems · 73 with full explanations
13 Easy47 Medium10 Hard
Sorting is often a preprocessing step that enables binary search, two-pointer sweeps, or greedy algorithms. C#'s Array.Sort() uses an introspective sort (O(n log n)). Custom comparisons use the Comparison<T> delegate or IComparer<T>. Consider counting sort or bucket sort for bounded integer inputs.
How to practice
To practice Sorting 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 sorting 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 Sorting problems
- 15.3SumMedium
- 16.3Sum ClosestMedium
- 56.Merge IntervalsMedium
- 75.Sort ColorsMedium
- 179.Largest NumberMedium
- 218.The Skyline ProblemHard
- 220.Contains Duplicate IIIHard
- 324.Wiggle Sort IIMedium
- 350.Intersection of Two Arrays IIEasy
- 368.Largest Divisible SubsetMedium
- 502.IPOUnknown
- 539.Minimum Time DifferenceMedium
- 611.Valid Triangle NumberMedium
- 646.Maximum Length of Pair ChainMedium
- 658.Find K Closest ElementsMedium
- 719.Find K-th Smallest Pair DistanceHard
- 757.Set Intersection Size At Least TwoUnknown
- 769.Max Chunks To Make SortedMedium
- 825.Friends Of Appropriate AgesMedium
- 826.Most Profit Assigning WorkMedium
- 857.Minimum Cost to Hire K WorkersHard
- 869.Reordered Power of 2Medium
- 905.Sort Array By ParityEasy
- 912.Sort an ArrayMedium
- 966.Vowel SpellcheckerMedium
- 973.K Closest Points to OriginMedium
- 976.Largest Perimeter TriangleMedium
- 1200.Minimum Absolute DifferenceEasy
- 1305.All Elements in Two Binary Search TreesUnknown
- 1331.Rank Transform of an ArrayUnknown
- 1353.Maximum Number of Events That Can Be AttendedMedium
- 1394.Find Lucky Integer in an ArrayUnknown
- 1465.Maximum Area of a Piece of Cake After Horizontal and Vertical CutsUnknown
- 1497.Check If Array Pairs Are Divisible by kMedium
- 1498.Number of Subsequences That Satisfy the Given Sum ConditionMedium
- 1508.Range Sum of Sorted Subarray SumsMedium
- 1509.Minimum Difference Between Largest and Smallest Value in Three MovesMedium
- 1636.Sort Array by Increasing FrequencyUnknown
- 1727.Largest Submatrix With RearrangementsUnknown
- 1751.Maximum Number of Events That Can Be Attended IIUnknown
- 1859.Sorting the SentenceUnknown
- 1877.Minimize Maximum Pair Sum in ArrayEasy
- 2008.Maximum Earnings From TaxiUnknown
- 2040.Kth Smallest Product of Two Sorted ArraysUnknown
- 2054.Two Best Non-Overlapping EventsUnknown
- 2070.Most Beautiful Item for Each QueryMedium
- 2071.Maximum Number of Tasks You Can AssignUnknown
- 2092.Find All People With SecretUnknown
- 2099.Find Subsequence of Length K With the Largest SumEasy
- 2141.Maximum Running Time of N ComputersUnknown
- 2161.Partition Array According to Given PivotMedium
- 2163.Minimum Difference in Sums After Removal of ElementsUnknown
- 2191.Sort the Jumbled NumbersUnknown
- 2206.Divide Array Into Equal PairsEasy
- 2225.Find Players With Zero or One LossesMedium
- 2273.Find Resultant Array After Removing AnagramsUnknown
- 2285.Maximum Total Importance of RoadsHard
- 2294.Partition Array Such That Maximum Difference Is KHard
- 2300.Successful Pairs of Spells and PotionsMedium
- 2342.Max Sum of a Pair With Equal Sum of DigitsMedium
- 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
- 2418.Sort the PeopleEasy
- 2471.Minimum Number of Operations to Sort a Binary Tree by LevelHard
- 2491.Divide Players Into Teams of Equal SkillMedium
- 2503.Maximum Number of Points From Grid QueriesHard
- 2551.Put Marbles in BagsHard
- 2554.Maximum Number of Integers to Choose From a Range IMedium
- 2563.Count the Number of Fair PairsMedium
- 2583.Kth Largest Sum in a Binary TreeMedium
- 2779.Maximum Beauty of an Array After Applying OperationUnknown
- 2780.Minimum Index of a Valid SplitMedium
- 2785.Sort Vowels in a StringMedium
- 2818.Apply Operations to Maximize ScoreUnknown
- 2839.Check if Strings Can be Made Equal With Operations IEasy
- 2840.Check if Strings Can be Made Equal With Operations IIMedium
- 2909.Minimum Sum of Mountain Triplets IIMedium
- 2948.Make Lexicographically Smallest Array by Swapping ElementsUnknown
- 2966.Divide Array Into Arrays With Max DifferenceMedium
- 3000.Maximum Area of Longest Diagonal RectangleMedium
- 3011.Find if Array Can Be SortedUnknown
- 3016.Minimum Number of Pushes to Type Word IIMedium
- 3024.Type of TriangleEasy
- 3025.Find the Number of Ways to Place People IUnknown
- 3027.Find the Number of Ways to Place People IIUnknown
- 3047.Find the Largest Area of Square Inside Two RectanglesEasy
- 3085.Minimum Deletions to Make String K-SpecialEasy
- 3169.Count Days Without MeetingsMedium
- 3186.Maximum Total Damage With Spell CastingMedium
- 3394.Check if Grid can be Cut into SectionsUnknown
- 3396.Minimum Number of Operations to Make Elements in Array DistinctMedium
- 3397.Maximum Number of Distinct Elements After OperationsUnknown
- 3433.Count Mentions Per UserMedium
- 3439.Reschedule Meetings for Maximum Free Time IEasy
- 3440.Reschedule Meetings for Maximum Free Time IIUnknown
- 3446.Sort Matrix by DiagonalsMedium
- 3531.Count Covered Buildings+Unknown
- 3562.Maximum Profit from Trading Stocks with DiscountsUnknown
- 3623.Count Number of Trapezoids IUnknown
- 3625.Count Number of Trapezoids IIUnknown
- 3661.Maximum Walls Destroyed by RobotsUnknown