Sort Characters By Frequency

Medium Solved

Description

Given a string s, sort it in decreasing order based on the frequency of characters.

The frequency of a character is the number of times it appears in the string. Return the sorted string.

Input format:

  • Line 1: String s

Examples

Input:
"tree"

Output:
"eert"
Input:
"cccaaa"

Output:
"cccaaa"
Input:
"Aabb"

Output:
"bbAa"

Note:

If multiple characters have the same frequency, their relative order does not matter.

No submissions yet.

Discuss hash maps, bucket sort, and sorting by frequency techniques.

Test Cases