How is count sort done when there are negative numbers available in the array?
Counting Sort w,r,t to negative elements in an array
hi @divisha30 you can modify the indices of the array to accomodate negative numbers as well
for eg if your range is from -10 to 10 for eg
you can make an array from 0-21
where 0th index will store frequency of -10 and so on
or you can use a map to store frequencies. If you use a map then it will also save space.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.