Coding

Sort a String by Frequency

Sort a string by the frequency of its characters.

Input: s = "cccaaa"

Output: "cccaaa" or "aaaccc"

Explanation: Both 'c' and 'a' appear three times, so sorting them by descending frequency keeps them grouped equally.

Was asked at

Practice this question with AI

First session is free - no credit card required.

Go Premium

More interviews, more skills, more success.

No answers yet

Be the first to share your approach to this question

Practice More Questions