← Back to challenges

Sort Characters by Frequency, Case, Alphabet

PythonHardalgorithmsconditionssortingstrings

Instructions

The function is given a string. Sort the characters and return a new string. Sorting conditions:

  • Most frequent move in front.
  • For the same frequency upper case characters move in front.
  • For the same frequency and case sort them alphabetically.

Examples

frequency_sort("tree") ➞ "eert"

frequency_sort("cccaaa") ➞ "aaaccc"

frequency_sort("Aabb") ➞ "bbAa"

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.