All problems

Does a Pricier Plan Mean More Watching?

mediumPythonMergeGroupBy

StreamVerse's product team has a hunch that premium subscribers watch more per session than basic ones. Plans are not priced the same way in every market, though, so a worldwide average would compare a premium subscriber in one country against a basic subscriber in another and call the difference a plan effect. The comparison is run one market at a time.

Subscribers

id name plan signup_date country
1 Ana Torres premium 2022-11-01 US
2 Ben Osei basic 2023-01-15 UK
3 Chloe Martin standard 2023-02-20 US
4 Dev Malhotra premium 2023-03-10 IN
5 Ella Novak basic 2023-04-05 UK

Watch events

id subscriber_id show_id watch_minutes watch_date
1 1 1 45 2023-05-01
2 1 5 60 2023-05-03
3 2 3 20 2023-05-02
4 3 2 55 2023-05-05
5 4 1 40 2023-05-06
6 4 4 70 2023-05-08
7 1 3 25 2023-05-10
8 3 5 50 2023-05-11
9 2 2 30 2023-05-12
10 5 4 65 2023-05-14

Input

Both tables above are already built for you — those rows are not read from input. What does arrive is a single line holding the market under review, spelled exactly as the country column spells it.

Task: Counting only sessions watched by subscribers in that country, print a dict mapping each plan → the average watch_minutes of those sessions, rounded to 2 decimals. A plan nobody in that market watched on does not appear at all, and a market with no viewing gives an empty dict rather than an error.

Example: if a single plan were watched in some market and its sessions averaged twenty minutes, you'd print {'basic': 20.0}.

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…