given an array A with n elements ranging in size from 1 to k
Untitled
Given array , get counts of each digit
Untitled
Then insert into array
ChatGPT Explanation
Counting Sort: This algorithm works by counting the number of occurrences of each distinct element in the array and then calculating the prefix sum of the counts to determine the position of each element in the final sorted array. It has a linear time complexity of O(n + k), where k is the range of the input values.