Intermediate Sorting Problems for Coding Interviews
77 intermediate Sorting problems from real coding interviews, each with test cases you can run online. By difficulty they split into 0 basic, 77 intermediate and 0 advanced. The companies that ask them most often are Google, Amazon, Meta, Bloomberg.
Solve a few problems of each level, name the pattern after each one and revisit the ones that needed a hint a week later. Practise stating the time and space complexity and the edge cases before you code.
Coding problems
- Minimum in a Rotated Sorted Array (Intermediate)
- Merge Intervals (Intermediate)
- Sort Characters by Frequency (Intermediate)
- Shortest Unsorted Middle Part (Intermediate)
- Array Frequency Analysis (Intermediate)
- Prime Factorization (Intermediate)
- Find K Closest Elements (Intermediate)
- Maximum Gap After Sorting (Intermediate)
- Shortest Unsorted Subarray Length (Intermediate)
- Top K Frequent Values (Intermediate)
- Minimum Swaps To Sort (Intermediate)
- Deduplicate Sorted Linked List (Intermediate)
- Binary Search Boundary (Intermediate)
- Minimum Operations to Sort by Reversals (Intermediate)
- Maximum Distance in Arrays (Intermediate)
- Find Intersection of Three Sorted Arrays (Intermediate)
- Median of Row-Wise Sorted Matrix (Intermediate)
- Search a Nearly Sorted Array (Intermediate)
- Split Array Into Consecutive Subsequences (Intermediate)
- Common Free Time (Intermediate)
- Remove All Repeated Values From Sorted List (Intermediate)
- Sort Linked List (Intermediate)
- Sort List Sorted by Absolute Values (Intermediate)
- Remove Values Appearing More Than Once (Intermediate)
- Brace Expansion (Intermediate)
- Find K Pairs With Smallest Sums (Intermediate)
- Interval List Intersections (Intermediate)
- 3Sum Triplets (Intermediate)
- Remove Duplicates Allowing Twice (Intermediate)
- Find First and Last Position (Intermediate)
- Search a 2D Matrix (Intermediate)
- Search a 2D Matrix II (Intermediate)
- Single Element in a Sorted Array (Intermediate)
- Kth Smallest in a Sorted Matrix (Intermediate)
- Search in Rotated Sorted Array II (Intermediate)
- Combination Sum (Intermediate)
- Combination Sum II (Intermediate)
- Combination Sum III (Intermediate)
- Palindrome Partitioning List (Intermediate)
- Restore IP Addresses (Intermediate)
- Combinations (Intermediate)
- Split String Into Descending Consecutive Values (Intermediate)
- Convert Sorted List to BST (Intermediate)
- Merge Two BSTs Into Sorted Order (Intermediate)
- Balance a Binary Search Tree (Intermediate)
- Minimum Swaps to Sort Tree Levels (Intermediate)
- Power of K-Size Subarrays (Intermediate)
- Sort Transformed Array (Intermediate)
- Missing Element in Sorted Array (Intermediate)
- Sum of Absolute Differences in a Sorted Array (Intermediate)
- Count Elements at Most X in Sorted Matrix (Intermediate)
- Single Teller Total Waiting Time (Intermediate)
- Stack Sortable Permutation Check (Intermediate)
- Longest Subarray of Consecutive Values (Intermediate)
- Inversion Table of Permutation (Intermediate)
- Bubble Sort Pass Count (Intermediate)
- Insertion Sort Comparison Count (Intermediate)
- Insertion Sort Shifts Per Element (Intermediate)
- Quick Sort Comparison Count (Intermediate)
- Quick Sort Partition Call Count (Intermediate)
- Quick Sort Recursion Depth (Intermediate)
- Merge Sort Comparison Count (Intermediate)
- Shell Sort Shift Count (Intermediate)
- Cocktail Shaker Sort Pass Count (Intermediate)
- Odd-Even Sort Round Count (Intermediate)
- Gnome Sort Step Count (Intermediate)
- Pancake Sort Flip Count (Intermediate)
- Binary Insertion Sort Comparison Count (Intermediate)
- Comb Sort Pass Count (Intermediate)
- Kaprekar Routine Steps (Intermediate)
- League Table Leader (Intermediate)
- Adjacent Swaps to Sort Letters (Intermediate)
- Rotations to Sort Ascending (Intermediate)
- Sum of Deviations From Median (Intermediate)
- Inversion Count of Small Values (Intermediate)
- Sort by Frequency Then Value (Intermediate)
- Boxes Fitting in a Container (Intermediate)
Related
Frequently asked questions
How do I get good at sorting problems?
Practise by level, name the pattern after you solve each problem and review the ones you needed hints for. The list is ordered so you can start with the basic ones.
Can I run sorting problems online here?
Yes. Each problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and more.