Ad-Free Sessions - Problem

You are given two tables: Playback and Ads.

The Playback table contains information about customer viewing sessions with start and end times. Each session has a unique session_id and belongs to a customer_id.

The Ads table contains information about ads shown to customers, with each ad having a unique ad_id, the customer_id who viewed it, and the timestamp when it was shown.

Task: Find all sessions that did not have any ads shown during them. A session runs during the inclusive interval between start_time and end_time. An ad is considered shown during a session if its timestamp falls within this interval.

Table Schema

Playback
Column Name Type Description
session_id PK int Unique identifier for each session
customer_id int ID of the customer watching this session
start_time int Start time of the session
end_time int End time of the session
Primary Key: session_id
Ads
Column Name Type Description
ad_id PK int Unique identifier for each ad
customer_id int ID of the customer who viewed this ad
timestamp int Time when the ad was shown
Primary Key: ad_id

Input & Output

Example 1 — Basic Ad-Free Session
Input Tables:
Playbook
session_id customer_id start_time end_time
1 1 1 3
2 1 4 5
3 2 4 5
Ads
ad_id customer_id timestamp
1 1 5
2 2 6
Output:
session_id
1
3
💡 Note:

Session 1 (customer 1, time 1-3): No ads shown during this period (ad was at time 5). Session 2 (customer 1, time 4-5): Has ad at time 5, so excluded. Session 3 (customer 2, time 4-5): No ads during this period (ad was at time 6).

Example 2 — All Sessions Have Ads
Input Tables:
Playbook
session_id customer_id start_time end_time
1 1 1 5
2 2 2 4
Ads
ad_id customer_id timestamp
1 1 3
2 2 4
Output:
session_id
💡 Note:

No ad-free sessions exist. Session 1 has an ad at time 3 (within range 1-5), and session 2 has an ad at time 4 (within range 2-4).

Constraints

  • 1 ≤ session_id, ad_id ≤ 100
  • 1 ≤ customer_id ≤ 100
  • 1 ≤ start_time ≤ end_time ≤ 300
  • 1 ≤ timestamp ≤ 300

Visualization

Tap to expand
Ad-Free Sessions Problem OverviewInput: Two TablesPlaybook (Sessions)session_id | customer_idstart_time | end_time1 | 1 | 1 | 3Adsad_id | customer_id | timestamp1 | 1 | 5LEFT JOIN+ NULL filterOutputAd-Free Sessionssession_id1🎯 Key Insight: Use LEFT JOIN to find sessions without matching adsSession 1: No ads between times 1-3 (ad was at time 5)
Understanding the Visualization
1
Input Tables
Playbook sessions and Ads data
2
LEFT JOIN
Join on customer and time overlap
3
Filter NULLs
Sessions with no matching ads
Key Takeaway
🎯 Key Insight: Use LEFT JOIN with NULL filtering to find records without matches
Asked in
Netflix 28 YouTube 19 Spotify 15
25.4K Views
Medium Frequency
~12 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen