Sorting & Searching
Classic sorting algorithms, custom comparators, and advanced search techniques
0/32 solved
Merge Sort & Divide-and-Conquer
Divide array in half, sort recursively, merge — stable O(n log n) sort
Approach
Divide array into halves, recursively sort each half, then merge the two sorted halves into one. During merge, perform any counting/aggregation needed at the combination step.
How to Recognize
Need to count inversions during sorting
Merge sort is the basis for many divide-and-conquer problems
Phrases like 'count inversions', 'reverse pairs', 'merge sort'
Need a stable sort that preserves relative order of equal elements
Pro Tips
Count inversions = count pairs (i,j) where i < j but a[i] > a[j]
Merge step is where counting happens — when an element from right comes before left
Can be used for custom sorting when comparison-based approaches are needed
8
Total
0
Easy
4
Medium
4
Hard
Time
O(n log n)
Space
O(n)