#C11755. Most Frequent Hashtag
Most Frequent Hashtag
Most Frequent Hashtag
You are given a list of social media posts. Each post is a string that may contain one or more hashtags. A hashtag is defined as a contiguous sequence of word characters (letters, digits, and underscores) that starts with the symbol #
.
Your task is to determine the most frequently occurring hashtag across all posts. In the case of a tie, return the hashtag that appears first in the order of occurrence in the input.
In mathematical terms, if we denote the number of occurrences of a hashtag \( h \) by \( f(h) \), then you are to find a hashtag \( h^* \) satisfying \[ h^* = \min \{ h : f(h) = \max_{h'} f(h') \} \text{ (in order of first occurrence)} \]
If there are no hashtags in any of the posts, output None
.
inputFormat
The first line contains an integer n
indicating the number of posts. Each of the following n
lines contains a post (a non-empty string).
outputFormat
Output a single line containing the most frequent hashtag. If no hashtag is found in any post, output None
.
4
#life is beautiful #happy
Enjoying #life #happy times
Just a random post
#happy vibes
#happy
</p>