Back to course home
0% completed
Solution: Frequency Sort
Problem Statement
Given a string, sort it based on the decreasing frequency of its characters.
Example 1:
Input: "Programming"
Output: "rrggmmPiano"
Explanation: 'r', 'g', and 'm' appeared twice, so they need to appear before any other character.
Example 2:
Input: "abcbab"
Output: "bbbaac"
Explanation: 'b' appeared three times, 'a' appeared twice, and 'c' appeared only once.
Constraints:
- 1 <= str.length <= 5 * 10<sup>5</sup>
- str consists of uppercase and lowercase English letters and digits.
.....
.....
.....
Like the course? Get enrolled and start learning!