Sorting · Easy
A text inspection panel displays each character once and ranks the most frequent characters first. Its output must remain identical across servers with different language settings. Spaces, punctuation and uppercase letters are meaningful input and must not be silently normalized.
Return distinct input characters ordered by descending occurrence count and then increasing ASCII code when counts tie.
Input
Call
- Implement solve(input) and return the result. The provided adapter handles JSON input and output.
Input shape
{ text: string }
Fields
- text contains printable ASCII characters with codes 32 through 126, including spaces. Case is significant.
Output
Return value
- Return an array of one-character strings, one per distinct character. Empty input returns [].
- Break equal-frequency ties by numeric ASCII code: space precedes punctuation, digits and letters; uppercase letters precede lowercase letters. Do not use locale-dependent collation.
Constraints
- 0 <= text.length <= 200000; input is printable ASCII only.
- Do not modify, trim, lowercase or otherwise normalize the supplied text.
Examples
Example 1
{
"text": "bAaab"
}Returns
[
"a",
"b",
"A"
]Example 2
{
"text": "aA "
}Returns
[
" ",
"A",
"a"
]Required complexity
O(n + a log(a + 1)) time and O(a) space where a <= 95 is the number of distinct characters