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.
In result vector, the frequency of the elements is stored, so suppose if "result[0] = 4" , this would mean there are 4 zeroes in our given array. Hence we would just push "0" 4 times in our sorted array (our final answer.) And to that - while(result[0]--) , this while loop will run until that 4 becomes 0, hence the "0" will get push_backed 4 times in "sorted" array.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Counting Sort 2
You are viewing a single comment's thread. Return to all comments →
In
result
vector, the frequency of the elements is stored, so suppose if "result[0] = 4" , this would mean there are 4 zeroes in our given array. Hence we would just push "0" 4 times in our sorted array (our final answer.) And to that -while(result[0]--)
, this while loop will run until that 4 becomes 0, hence the "0" will get push_backed 4 times in "sorted" array.