PracHub
QuestionsCoachesLearningGuidesInterview Prep

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.

Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ 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
  • AI Coding 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.

Related Coding Questions

  • Monthly Cohort Retention - Amazon (medium)
  • 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)