7 kyu

Most common first

331 of 353mentalplex

Description:

Given a string, s, return a new string that orders the characters in order of frequency.

The returned string should have the same number of characters as the original string.

Make your transformation stable, meaning characters that compare equal should stay in their original order in the string s.

most_common("Hello world") => "lllooHe wrd"
most_common("Hello He worldwrd") => "lllHeo He wordwrd"
most_common("Hello world") => "lllooHe wrd"
most_common("Hello He worldwrd") => "lllHeo He wordwrd"

Explanation:

In the hello world example, there are 3 'l'characters, 2 'o'characters, and one each of 'H', 'e', ' ', 'w', 'r', and 'd'characters. Since 'He wrd'are all tied, they occur in the same relative order that they do in the original string, 'Hello world'.

Note that ties don't just happen in the case of characters occuring once in a string. See the second example, most_common("Hello He worldwrd")should return 'lllHeo He wordwrd', not 'lllHHeeoo wwrrdd'. This is a key behavior if this method were to be used to transform a string on multiple passes.

Fundamentals

Stats:

CreatedAug 2, 2017
PublishedAug 2, 2017
Warriors Trained945
Total Skips27
Total Code Submissions1758
Total Times Completed353
Python Completions331
R Completions27
Total Stars13
% of votes with a positive feedback rating83% of 127
Total "Very Satisfied" Votes96
Total "Somewhat Satisfied" Votes19
Total "Not Satisfied" Votes12
Total Rank Assessments15
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • mentalplex Avatar
  • Bubbler Avatar
  • saudiGuy Avatar
Ad