#C12992. Word Frequency Counter
Word Frequency Counter
Word Frequency Counter
You are given a text string, possibly containing punctuation and special characters. Your task is to count the frequency of each unique word in the string. The word matching should be case-insensitive, and all punctuation and special characters should be ignored.
After processing the input string, output a JSON object where the keys are the words and the values are their corresponding counts. The keys in the JSON object must be in lexicographical order (i.e. sorted alphabetically). For example, if the input is The quick, brown fox!
, then the output should be {"brown":1,"fox":1,"quick":1,"the":1}
.
Note: Read the entire input from stdin
and output the result to stdout
without any additional formatting.
inputFormat
A single string provided via standard input (stdin). This string may span multiple lines and contains letters, numbers, punctuation, and special characters.
outputFormat
A single line JSON object printed to standard output (stdout) representing the frequency count of each word. The JSON object keys should be sorted in lexicographical order and the object should have no additional whitespace.## sample
The quick brown fox jumps over the lazy dog. The dog was not amused by the quick jump.
{"amused":1,"brown":1,"by":1,"dog":2,"fox":1,"jump":1,"jumps":1,"lazy":1,"not":1,"over":1,"quick":2,"the":4,"was":1}