PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Data Manipulation (SQL/Python)/Amazon

Find recommended friend pairs by shared listening

Last updated: Mar 29, 2026

Quick Overview

This question evaluates the ability to perform time-based deduplication, aggregation and pairwise matching using SQL (joins, grouping, and anti-joins), along with handling unordered user pairs and extracting calendar dates from timestamps, and falls under the Data Manipulation (SQL/Python) domain.

  • easy
  • Amazon
  • Data Manipulation (SQL/Python)
  • Data Scientist

Find recommended friend pairs by shared listening

Company: Amazon

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Technical Screen

## Problem (SQL) You work on a music app and want to recommend new friend connections based on listening similarity. ### Tables Assume the following schemas: **listens** - `user_id` (BIGINT) - `song_id` (BIGINT) - `listened_at` (TIMESTAMP) **friendships** (undirected friendship; may be stored as one row per pair) - `user_id_1` (BIGINT) - `user_id_2` (BIGINT) - `created_at` (TIMESTAMP) ### Definitions / assumptions - Two users have an *overlapping song* on a given day if **both** listened to the **same `song_id`** on that **same calendar date**. - Count **distinct** overlapping songs per pair per day (ignore repeat listens of the same song). - Treat pairs as **unordered** (e.g., output `(min_user, max_user)`). - A pair should be recommended only if they are **not already friends** (no matching pair in `friendships`, regardless of ordering). - Unless stated otherwise, treat `listened_at` as UTC when deriving the calendar `date`. ### Task Write a SQL query to return all recommended pairs of users `(user_id_a, user_id_b)` such that there exists at least one day where they listened to **more than 3** of the **same songs** on that day. ### Output Return: - `user_id_a` - `user_id_b` - `listen_date` - `overlap_song_count` Only include rows where `overlap_song_count > 3` and the pair is not already in `friendships`.

Quick Answer: This question evaluates the ability to perform time-based deduplication, aggregation and pairwise matching using SQL (joins, grouping, and anti-joins), along with handling unordered user pairs and extracting calendar dates from timestamps, and falls under the Data Manipulation (SQL/Python) domain.

Related Interview Questions

  • Find recommended friend pairs by shared songs - Amazon (medium)
  • Write SQL window functions for D7 retention - Amazon (medium)
  • Find daily first-order merchants with SQL - Amazon (Medium)
  • Design student–course data models and SQL - Amazon (Medium)
  • Implement robust word counts and min/max - Amazon (Medium)
Amazon logo
Amazon
Nov 20, 2025, 12:00 AM
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
3
0

Problem (SQL)

You work on a music app and want to recommend new friend connections based on listening similarity.

Tables

Assume the following schemas:

listens

  • user_id (BIGINT)
  • song_id (BIGINT)
  • listened_at (TIMESTAMP)

friendships (undirected friendship; may be stored as one row per pair)

  • user_id_1 (BIGINT)
  • user_id_2 (BIGINT)
  • created_at (TIMESTAMP)

Definitions / assumptions

  • Two users have an overlapping song on a given day if both listened to the same song_id on that same calendar date .
  • Count distinct overlapping songs per pair per day (ignore repeat listens of the same song).
  • Treat pairs as unordered (e.g., output (min_user, max_user) ).
  • A pair should be recommended only if they are not already friends (no matching pair in friendships , regardless of ordering).
  • Unless stated otherwise, treat listened_at as UTC when deriving the calendar date .

Task

Write a SQL query to return all recommended pairs of users (user_id_a, user_id_b) such that there exists at least one day where they listened to more than 3 of the same songs on that day.

Output

Return:

  • user_id_a
  • user_id_b
  • listen_date
  • overlap_song_count

Only include rows where overlap_song_count > 3 and the pair is not already in friendships.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Data Manipulation (SQL/Python)•More Amazon•More Data Scientist•Amazon Data Scientist•Amazon Data Manipulation (SQL/Python)•Data Scientist Data Manipulation (SQL/Python)
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.