Sort Characters by Frequency, Case, Alphabet

Published by Mubashir Hassan in

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

  • Most frequent (case-specific) 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

Watch a quick demo on how Edabit works.