#C12869. Most Frequent Word
Most Frequent Word
Most Frequent Word
Given a string s, find the most frequently occurring word. The word matching is case-insensitive. In case of ties (i.e. multiple words with the same maximal frequency), choose the word that appears first in the string.
Formally, let the input string be represented as a sequence of words \( w_1, w_2, \dots, w_n \). For each word \( w \), define its frequency as \( f(w) \). The answer is the word \( w^* \) such that \[ w^* = \arg\max_{w \in \{w_1,\dots,w_n\}} f(w), \] with ties broken by the order of appearance in the input.
If the input string is empty, output None
.
inputFormat
The input consists of a single line, which is a string containing words separated by spaces. The string can be empty.
outputFormat
Output a single line containing the most frequent word (in lowercase). If the input string is empty, output None
.
apple
apple