Sort a Bounded Integer Range
Sort integers from a small range by counting how often each value appears.
The problem
Implement counting_sort(values). values is a list of integers that may be negative and may repeat, and the gap between the smallest and largest value is small. Return a new list with the same integers in ascending order. Do not call sorted or list.sort: use counting sort, which counts how many times each value appears and rebuilds the list from those counts.
Starter code
def counting_sort(values):
passPublic examples
values = [3, -1, 2, -1]gives[-1, -1, 2, 3]values = [4, 4]gives[4, 4]
Solving it in the practice book needs an active paid plan.
Open it in the practice bookOne thought at a time.
