The problem asked to do this in lesser than O[nlogn] time. Counting sort has O[n] time, so applied that straight.
def sort_scores(unsorted_scores, highest_score) counts = [0] * (highest_score + 1) unsorted_scores.each do |score| counts[score] += 1 end sorted_score = [] highest_score.downto(1).each do |score| count = counts[score] (0...count).each do |i| sorted_score << score end end sorted_score end
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
The problem asked to do this in lesser than O[nlogn] time.
Counting sort has O[n] time, so applied that straight.