Feature #7: Trending Hashtags

Implementing the "Trending Hashtags" feature for our "Twitter" project.

Description

We are given a list, tweets_info, which is a daily log of hashtags used by some people in their tweets. The log is structured as follows:

  • the day on which the tweet was posted,
  • all the people who posted on that day, and
  • the hashtag they used in their tweet on that day.

Our task is to group and return all the people who used the same set of hashtags in one of their tweets, along with the day on which they tweeted with those hashtags. The output list will consist of day/person strings for all hashtags that have at least two mentions in the input. We can return the answer in any order.

A single day information string in the input list has the following format:

  • "day_m p1(p1_hashtag) p2(p2_hashtag) ... pn(pn_hashtag)"

It means that on the day day_m, there are n people (p1,p2,...,pn) with hashtag they used in their tweet (p1_hashtag,p2_hashtag,...,pn_hashtag) respectively. Note that n >= 1 and m >= 0. If m = 0 it means the day is Monday, m = 1 it means the day is Tuesday and so on.

The output is a list of strings. Each string should be of the form day_1/p1 day_2/p2 if p1 and p2 tweeted with the same hashtag on day1 and day2, respectively. In the rest of the lesson, we’ll refer to the day, followed by a forward slash, followed by a person’s name, as the hashtag path, as shown below:

  • day/person_name

Constraints

  • We can assume that no person shares the same name in the same string in the tweet_info list.
  • A single blank space separates the day and tweet info.

The following examples might clarify these requirements:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.