708. Sort Characters by Frequency
0
Medium
Given a string `S`, arrange its characters in descending order based on their frequency. The frequency of a character is the number of times it appears in the string.
Output the sorted string.
***Note: If two characters have the same frequency, sort them in lexicographical order.***
Input Format
A single line containing a string S.
Output Format
Print the sorted string.
Example
Input
aabbbcc
Output
bbbaacc
Constraints
1 <= s.length <= 10^5
S consists of uppercase and lowercase English letters and digits.
Loading...
View Submissions
Console