AnalystPath

Podcast Pairs Sharing the Most Subscribers

PandasMediumMid level~10 min

Problem

You are given one DataFrame `subscriptions`:

| Column | Type |
|-------------|------|
| podcast_id | int |
| listener_id | int |

`(podcast_id, listener_id)` is unique. Each row means the listener subscribes to that podcast.

Find every **pair of podcasts that share the maximum number of common subscribers**. If the largest number of subscribers shared by any two podcasts is `maxShared`, return all podcast pairs that share exactly `maxShared` subscribers.

In each returned pair the smaller `podcast_id` must appear first, in columns `podcast1_id` and `podcast2_id`. Return the result in any order.

Input data

Example rows — the live problem includes the full dataset.

subscriptions
podcast_idlistener_id
110
210
111
211
311

Expected output

Your answer should return 1 row with the columns podcast1_id, podcast2_id.

Starter code (Pandas (Python))

import pandas as pd

def podcast_pairs_sharing_the_most_subscribers(subscriptions: pd.DataFrame) -> pd.DataFrame:
    # Your code here
    return subscriptions

Solve this Pandas question free

Write Pandas (Python) and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related Pandas questions