Python code: Given an array of colors represented by numbers 0, 1, and 2, sort them using counting sort:
Counting Sort is a linear sorting algorithm that works well when the range of input values is known and relatively small. In this case, you want to sort an array…