Sort Characters By Frequency Problem
Sort Characters By Frequency Problem — ExecCode Medium DSA Practice
Solve the Sort Characters By Frequency problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given a string s, sort it in decreasing order based on the frequency of its characters and return the sorted string. If two characters share a frequency, order them alphabetically so the result is deterministic.
Examples
Input s = "aabbcccddd"; Output "cccdddaabb". Input s = "tree"; Output "eert". Input s = "cccaaa"; Output "aaaccc"
Constraints
1 ≤ s.length ≤ 5 × 10⁵ s consists of uppercase and lowercase English letters and digits
Practice Sort Characters By Frequency free on ExecCode. Browse DSA problems, topic map, and placement guides.