Python Interview Prep/Premium vs Freemium
Microsoft logo

Premium vs Freemium

Microsoft·medium·pandas·About 20 min in the room

Three tables are on the bench: downloads (user_id, date, downloads), users (user_id, acc_id) and accounts (acc_id, paying_customer, which is yes or no). Find the dates on which non-paying customers downloaded more in total than paying customers. Return result with the columns date, non_paying and paying (each day's total downloads for that group), in date order.

The data

downloads22 rows
user_idint64dateobjectdownloadsint64
12025-02-014
22025-02-012
32025-02-016
42025-02-011
52025-02-013
62025-02-015
and 16 more rows
users6 rows
user_idint64acc_idint64
1101
2101
3102
4103
5104
6104
accounts4 rows
acc_idint64paying_customerobject
101yes
102no
103yes
104no

Target output

datenon_payingpaying
2025-02-01147
2025-02-0363
2025-02-0465
2025-02-0530

What this question tests

Tests a three-table merge and a pivot from long to wide, then a comparison across the new columns. The trap is a date where only one side downloaded anything: after the pivot that side is missing, not zero, and a comparison with a missing value is never true.

More Python interview questions

  • Weeks at Number One · Spotify · easy
  • The Salary Gap · LinkedIn · easy
  • Month-over-Month Revenue · Amazon · medium
  • Back Within a Week · Amazon · medium
Python
Shift+EnterPython is starting in your browser...
Output

Starting Python...