Tap here to switch tabs
Problem
Submissions

Problem: Sort Characters By Frequency

Sort Characters By Frequency asks you to reorder a string so each character's occurrences stay together, with more frequent characters placed before less frequent ones. Ties may appear in any order.

Statement

Given a string s, reorder its characters so that characters with higher frequency appear before characters with lower frequencies.

All occurrences of the same character must be placed contiguously. If multiple characters have the same frequency, they may appear in any order.

Constraints:

  • 1≤1 \leq s.length ≤5⋅105\leq 5 \cdot 10^5

  • s consists of uppercase English letters, lowercase English letters, and digits

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Sort Characters By Frequency

Sort Characters By Frequency asks you to reorder a string so each character's occurrences stay together, with more frequent characters placed before less frequent ones. Ties may appear in any order.

Statement

Given a string s, reorder its characters so that characters with higher frequency appear before characters with lower frequencies.

All occurrences of the same character must be placed contiguously. If multiple characters have the same frequency, they may appear in any order.

Constraints:

  • 1≤1 \leq s.length ≤5⋅105\leq 5 \cdot 10^5

  • s consists of uppercase English letters, lowercase English letters, and digits