#C13779. Word Frequency Histogram and Most Frequent Word

    ID: 43354 Type: Default 1000ms 256MiB

Word Frequency Histogram and Most Frequent Word

Word Frequency Histogram and Most Frequent Word

You are given a sentence. Your task is to compute two things:

  • A word frequency histogram, which counts how many times each word appears in the sentence. The histogram should be built in a case-insensitive manner, and all punctuation should be ignored.
  • The most frequently occurring word in the sentence. In case of a tie, the word that appears first in the sentence (after processing) should be chosen.

Note: For punctuation removal, consider all characters defined in the standard punctuation set. You are advised to output the histogram as a JSON object with keys as words and values as their corresponding counts, and then output the most frequent word on the next line.

Example:

Input:
Hello, world! Hello.

Output: {"hello": 2, "world": 1} hello

</p>

inputFormat

The input consists of a single line containing a sentence. The sentence may include letters, spaces, and punctuation.

outputFormat

The output should be two lines:

  • The first line is the word frequency histogram in JSON format (a dictionary with word keys and integer frequency values). The keys must be in the order they appear in the sentence (after punctuation removal and conversion to lowercase).
  • The second line is the most frequent word in the sentence. In case of a tie, the word that appears first in the sentence should be printed.
## sample
Hello world
{"hello": 1, "world": 1}

hello

</p>