Problema
Count every character in text except spaces. Report each distinct character once as "character:count", sorted by character code (so uppercase letters come before lowercase).
Implement character_frequency(text).
Input
text: The text to count (ASCII characters).
Output
Return the list of "character:count" entries.
Restrições
0 ≤ length ≤ 10,000
Exemplos
Entrada:
text = "hello"
Saída esperada:
expected = ["e:1", "h:1", "l:2", "o:1"]
Entrada:
std::string text = "hello";
Saída esperada:
std::vector<std::string> expected = {"e:1", "h:1", "l:2", "o:1"};
Entrada:
string text = "hello";
Saída esperada:
string[] expected = new string[] {"e:1", "h:1", "l:2", "o:1"};
Explicação
e:1, h:1, l:2, o:1 sorted by character: ["e:1", "h:1", "l:2", "o:1"].
Entrada:
text = "a a A"
Saída esperada:
expected = ["A:1", "a:2"]
Entrada:
std::string text = "a a A";
Saída esperada:
std::vector<std::string> expected = {"A:1", "a:2"};
Entrada:
string text = "a a A";
Saída esperada:
string[] expected = new string[] {"A:1", "a:2"};
Explicação
Spaces are skipped; "A" sorts before "a": ["A:1", "a:2"].
Como abordar
Tente sozinho primeiro e depois abra uma dica de cada vez.
Dica 1
Skip spaces, but count every other ASCII character exactly as it appears.
Dica 2
Accumulate counts in a frequency table, then output distinct characters once.
Dica 3
Sort by character code so uppercase and lowercase order naturally follows ASCII.
Complexidade esperada
O(n + m log m) time, O(m) extra space
Referências
Este desafio foi adaptado para o CodeUtility. Siga o enunciado e as restrições acima.