We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Counting Sort 1
- Discussions
Counting Sort 1
Counting Sort 1
Sort by
recency
|
649 Discussions
|
Please Login in order to post a comment
in python: * def countingSort(arr): * # Write your code here * result = [0]*100 * for i in range(len(arr)): * result[arr[i]]+= 1 * return result
JS Solution:
function countingSort(arr) { return Object.values( arr.reduce((acc, cur) => { acc[cur] = (acc[cur] || 0) + 1; return acc; }, new Array(100).fill(0)) ); }
First one is better cause you don't have to count the number with zero freq.
js single line solution: