#K42542. Frequency Based Character Sorting
Frequency Based Character Sorting
Frequency Based Character Sorting
Given a string ( s ), sort its characters in descending order based on their frequency. If two characters have the same frequency, they must appear in the order of their first occurrence in ( s ). For instance, if ( s = \text{'tree'} ), the expected output is ( \text{'eetr'} ). The input is provided via standard input and the output should be printed to standard output.
inputFormat
Input consists of a single line containing the string ( s ). The string may include letters, digits, and special characters, and its length can be zero or more.
outputFormat
Print the string with characters sorted by frequency (in descending order) and by the order of their first appearance when frequencies are equal.## sample
tree
eetr