Sort Characters By Frequency

Given a string, sort it in decreasing order based on the frequency of the characters. Return the sorted string, allowing multiple correct answers if applicable. Characters with the same frequency should be grouped together.

Constraints

  • 1 <= s.length <= 5 * 10^5
  • s consists of uppercase and lowercase English letters and digits.
Saving… · 2 lines
class Solution:
def sortCharactersByFrequency(self, s: str) -> str:
Console

Click Run to execute sample tests.