Most Active Users
GoogleMedium
A messaging service logs who talked to whom. Each log entry is a string of two user names joined by one hyphen, such as "ann-bo". Names are non-empty, case-sensitive, and contain only letters and digits.
Implement top_users(pairs) where pairs is the list of log entries.
Part 1: Rank users by activity
Every entry adds 1 to the activity count of both users in it.
Return the names of all users that appear in at least one entry, ordered by count from highest to lowest. Users with equal counts are ordered by name, ascending, using ordinary string comparison.
- Example 1
- pairs
["ann-bo","bo-cy","ann-cy","bo-dee","bo-eli"]- Output
["bo","ann","cy","dee","eli"]
Why:
bois in 4 pairs,annandcyin 2 each, anddeeandeliin 1 each. Ties are ordered by name, so the result isbo,ann,cy,dee,eli.
Constraints
0 <= len(pairs) <= 10^5pairs[i].split('-')[0] != pairs[i].split('-')[1]- For
i != j,pairs[i].split('-') != pairs[j].split('-')andpairs[i].split('-') != pairs[j].split('-')[::-1] 1 <= len(name) <= 20for every namenameinpairs[i].split('-')
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.