Compute multi-account user distribution and unread pct
MetaData Scientist · Technical ScreenLast updated
This question evaluates a data scientist's ability to perform relational data manipulation and aggregation with SQL or Python, covering competencies such as handling one-to-many joins, grouping and bucketing counts, deduplicating across related tables, and computing cohort-level percentages from boolean flags.
You are working on a product where a user can have multiple accounts, and each account can receive notifications.
Tables
Assume the following schemas:
users
user_idBIGINT PRIMARY KEYcreated_atTIMESTAMP
accounts
account_idBIGINT PRIMARY KEYuser_idBIGINT NOT NULL REFERENCESusers(user_id)created_atTIMESTAMP
notifications
notification_idBIGINT PRIMARY KEYaccount_idBIGINT NOT NULL REFERENCESaccounts(account_id)created_atTIMESTAMPis_readBOOLEAN --FALSEmeans unread
Tasks
- Account-count distribution: Return the number of users who have:
- exactly 2 accounts
- exactly 3 accounts
- 4 or more accounts
Required output columns: account_bucket, num_users.
- Unread-notification rate among multi-account users: Among users with 2+ accounts, compute the percentage of users who have at least one unread notification across any of their accounts.
Required output columns: pct_users_with_unread (as a percent or decimal; specify which you choose).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.