Counting sort

A non-comparison sorting algorithm that works if the elements fit into a range of small positive integers. It works by counting the number of each integers and then outputting it in sorted order by using those counts.

Pros Cons
Better than O(n log n) if the range of values (k) is less than log n Limited in usage for only integer lists with a small range
Is stable
LeetCode Problems
Merge Intervals
Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input.

Performance
Worst-case O(n+k)
Worst-case space O(n+k)

Similar