Amazon Interview Question: Find Top X Most Frequent Tags from Friends and Friends-of-Friends (Graph + Frequency Counting)

20 Views
No Comments

Imagine you have a Twitter-style social network.
Each post can have multiple tags.

Your task:

Return the top X most frequent tags used by your friends and your friends-of-friends.

In other words, starting from a given user:

  • Look at all friends (1-hop)
  • Look at all friends of friends (2-hop)
  • Aggregate all tags from all posts of those users
  • Return the Top X frequent tags

Example (conceptual):

User → friends: A, B
A’s tags: ["sports", "fun"]
B’s tags: ["news", "sports"]
A’s friends: C
C’s tags: ["travel", "sports"]

If X = 2, output:

["sports", "fun"]      # For example (depends on actual counts)

Use BFS up to depth 2 to collect friends and friends-of-friends.
Count tag frequencies with a hash map, then return the top X using a min-heap or sorting.

The VOprep team has long accompanied candidates through various major company OAs and VOs, including Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for these companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.

END
 0