Skip to content

Instantly share code, notes, and snippets.

@mrchocoborider
Created September 10, 2018 18:58
Show Gist options
  • Save mrchocoborider/120f3783d6988153556461a9fe9aca30 to your computer and use it in GitHub Desktop.
Save mrchocoborider/120f3783d6988153556461a9fe9aca30 to your computer and use it in GitHub Desktop.
Interviewcake.com algorithmic pattern practice #2, Parker's solution.
def sort_scores(unsorted_scores, highest_possible_score):
# List of 0s at indices 0..highest_possible_score
score_counts = [0] * (highest_possible_score+1)
# Populate score_counts
for score in unsorted_scores:
score_counts[score] += 1
# Populate the final sorted list
sorted_scores = []
# For each item in score_counts
for score in xrange(len(score_counts) - 1, -1, -1):
count = score_counts[score]
# For the number of times the item occurs
for time in xrange(count):
# Add it to the sorted list
sorted_scores.append(score)
return sorted_scores
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment