Twitter Trends
Practice
3.7 (42 votes)
Data structures
Easy
Sorting
String manipulation
Approved
Problem
82% Success 2863 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Twitter shows trends in order to make its users aware of the trending news. These trends are nothing but trending hashtags that the users are tweeting about. For example: If thousands of users are talking about United States by adding a hashtag #US in their tweet, then US will be a trending hashtag. Couple of example tweets with hashtag #US could be:

  • Donald Trump becomes the 45th #US President
  • Roger Federer wins #US Open for 5th time

Given a list of N tweets, your task is to find top the five trending hashtags. Each tweet, let's call it S, will contain at least one one word with hashtag. There will be maximum of three hashtags in any tweet. All hashtags in a single tweet will be unique.

Input:
First line of the input will contain N denoting the number of tweets.
Next N lines, each will contain a string S.

Output:
Print the top five trending hashtags. In case of tie between any two hashtags, print them in lexicographical order in a new line.

Constraints:

  • \( 10 \le N \le 10^{3}\)
  • \( 1 \le |S| \le 140 \) where S denotes length of string S i.e. length of tweet.
  • Any hashtag denoted by H \( 1 \le |H| \le 20 \) where H denotes length of any hashtag H.

Note:

  • Any tweet is composed of lowercase and uppercase English letters, digits and spaces.
  • Any hashtag begins with # and the subsequent characters will only contain lowercase and uppercase English letters and digits.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
9 votes
Tags:
AlgorithmsEasyString Manipulation
Points:20
3 votes
Tags:
String AlgorithmsReal worldAlgorithmsString Searching
Points:30
70 votes
Tags:
ReadyMathematicsMedium