Best Friends List

ASKED IN INTERVIEW
2pts
Snap

Problem Statement

Snapchat uses interaction frequency to determine a user’s "Best Friends." These are the people you communicate with most frequently on the platform.

Write an SQL query to find the top 3 friends that user_id 100 has interacted with most.

Rules:

  • Consider only interactions where user_id is 100.
  • Total interactions are calculated as the count of records for each friend_id.
  • If multiple friends have the same interaction count, rank them by friend_id in ascending order.
  • Output columns: friend_id, interaction_count.
  • Return the results in descending order of interaction_count.

Table Schema:

  • Interactions: interaction_id, user_id, friend_id, interaction_type (Snap, Chat, Story), created_at.
Tests your understanding of
Basic SQL, Aggregation, Grouping and Limiting

Input Tables

Interactions
user_id(INTEGER)friend_id(INTEGER)interaction_type(VARCHAR)
100201Snap
100202Chat
100201Snap
100203Story
100202Snap
100201Chat
100204Snap
100202Chat
100205Snap

Expected Output

friend_id(INTEGER)interaction_count(INTEGER)
2013
2023
2031

Tags

EasyASKED IN INTERVIEWBasic SQLAggregationGroupingLimiting
10 min
78%

Hints