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.
yes
Basically, counting sort on the concept count the frequency of the elements present in the array and based on that initialize into another temporary array the array according to their frequency in increasing order or decreasing order as per our requirements.
In my code I applied the given logic:
1) Firstly, I find the length of given vector that we have to sort.
2) Secondly, the maximum size of returning array given 100 that's why whole array initialize with 0s.
3) After that by using the given array updated the value in ans array
for example: if element in given array is 5 then, we go to index 5 of ans array and increase value by 1 beacuse we have to find the frequency of each element to sort the array.
4) finally, return the array called ans.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Sort 1
You are viewing a single comment's thread. Return to all comments →
yes Basically, counting sort on the concept count the frequency of the elements present in the array and based on that initialize into another temporary array the array according to their frequency in increasing order or decreasing order as per our requirements. In my code I applied the given logic: 1) Firstly, I find the length of given vector that we have to sort. 2) Secondly, the maximum size of returning array given 100 that's why whole array initialize with 0s. 3) After that by using the given array updated the value in ans array for example: if element in given array is 5 then, we go to index 5 of ans array and increase value by 1 beacuse we have to find the frequency of each element to sort the array. 4) finally, return the array called ans.