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.
If the range of number in a array is between [0,9], then we can create a count array of size 10, where i'th elements can store the number of times integer i occured in the original array. Lets say we have a array: {7, 2, 7, 1, 5} Then our count will have element count[1] = 1, count [2] = 1, count[5] = 1, count[7] = 2 and other elements of count will be zero. Hope that this will help.
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 →
If the range of number in a array is between [0,9], then we can create a count array of size 10, where i'th elements can store the number of times integer
i
occured in the original array. Lets say we have a array:{7, 2, 7, 1, 5}
Then ourcount
will have elementcount[1] = 1, count [2] = 1, count[5] = 1, count[7] = 2
and other elements of count will be zero. Hope that this will help.