#C18. Twitter Trending Hashtag Score Calculator

    ID: 45044 Type: Default 1000ms 256MiB

Twitter Trending Hashtag Score Calculator

You are given a sequence of tweets, where each tweet is represented as a list of hashtags. Your task is to calculate the trending score for each hashtag. For a total of (T) tweets, the weight assigned to a hashtag in the (i)-th tweet (0-indexed) is (T - i) (i.e. the first tweet has weight (T), the second tweet (T-1), and so on). The trending score of a hashtag is the sum of the weights from all tweets in which it appears. Read input from standard input and output a JSON-formatted dictionary (object) where each key is a hashtag and its corresponding value is the trending score. The dictionary should have its keys in lexicographical order.

inputFormat

Input is read from standard input. The first line contains an integer (T) representing the number of tweets. Each of the next (T) lines starts with an integer (K), the number of hashtags in that tweet, followed by (K) hashtags separated by spaces. For example:

3 2 #python #coding 3 #python #development #coding 2 #development #java

outputFormat

Output a JSON-formatted dictionary (on a single line) where the keys are hashtags (strings) and the values are their trending scores (integers). The keys must be in lexicographical order. For example:

{"#coding": 5, "#development": 3, "#java": 1, "#python": 5}## sample

1
1 #python
{"#python": 1}