समस्या
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.
सीमाएँ
0 ≤ length ≤ 10,000
उदाहरण
इनपुट:
text = "hello"
अपेक्षित आउटपुट:
expected = ["e:1", "h:1", "l:2", "o:1"]
इनपुट:
std::string text = "hello";
अपेक्षित आउटपुट:
std::vector<std::string> expected = {"e:1", "h:1", "l:2", "o:1"};
इनपुट:
string text = "hello";
अपेक्षित आउटपुट:
string[] expected = new string[] {"e:1", "h:1", "l:2", "o:1"};
व्याख्या
e:1, h:1, l:2, o:1 sorted by character: ["e:1", "h:1", "l:2", "o:1"].
इनपुट:
text = "a a A"
अपेक्षित आउटपुट:
expected = ["A:1", "a:2"]
इनपुट:
std::string text = "a a A";
अपेक्षित आउटपुट:
std::vector<std::string> expected = {"A:1", "a:2"};
इनपुट:
string text = "a a A";
अपेक्षित आउटपुट:
string[] expected = new string[] {"A:1", "a:2"};
व्याख्या
Spaces are skipped; "A" sorts before "a": ["A:1", "a:2"].
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
Skip spaces, but count every other ASCII character exactly as it appears.
संकेत 2
Accumulate counts in a frequency table, then output distinct characters once.
संकेत 3
Sort by character code so uppercase and lowercase order naturally follows ASCII.
अपेक्षित जटिलता
O(n + m log m) time, O(m) extra space
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।