this code for counting sort is showing TLE
how can i optimize??
https://ide.codingblocks.com/#/s/13890
Counting sort doubt
1 Like
Hi, apoorva
You can simply create an array, say cnt[1000000] initialized with 0 and increment the value of cnt[arr[i]] as you encounter arr[i] in your array. And, you would require a nested loop to print the sorted array(incrementing with value as index optimizes the code).
If you have any further doubts, let me know…
thanks it worked
1 Like