Compute each member’s current notification status
LinkedInData Scientist · Technical ScreenLast updated
A LinkedIn data scientist SQL screen: given an end-of-January notification-status snapshot and a February log of turn_on/turn_off actions, compute each member's current status as of 2020-02-29, keeping members from either table. Follow-ups explore reconstructing state when the action log has no date column — unsolvable in general, but recoverable via action-count parity when every action is a guaranteed valid transition.
Question
You are given two tables describing LinkedIn members’ push-notification settings. Compute each member’s current notification status as of 2020-02-29 by combining the end-of-January baseline with the toggle actions recorded during February.
Tables
status — each member’s latest setting as of 2020-01-31
member_idINTstatusVARCHAR —'on'or'off'
actions — all notification-toggle actions taken during February 2020
member_idINTaction_dateDATE — a UTC calendar date between2020-02-01and2020-02-29actionVARCHAR —'turn_on'or'turn_off'
Assumptions
- A member performs at most one action per day.
- Every
actionsrow occurs after the2020-01-31snapshot. actionsmay include new members not present instatus(e.g., a member created after2020-01-31).
Tasks
- Return each member’s current notification status as of
2020-02-29.
- Include every member who appears in either table — members only in
status, members only inactions, and members in both. - If a member has at least one February action, their status is determined by their latest February action (
turn_on→'on',turn_off→'off'). - If a member has no February action, their status remains the
statusvalue from2020-01-31. - Output columns:
member_id,current_status.
-
Follow-up A — no date column. Suppose
actionsno longer containsaction_date, so you cannot order the actions. Explain whether the final status can still be reconstructed, and specify what additional data, assumptions, or table design would be required to make the problem solvable. -
Follow-up B — no date column, valid-transition guarantee. Now add the assumption that every recorded action is a valid state transition from the member’s previous state (a
turn_ononly ever follows an'off'state and vice versa, so no contradictory or repeated actions occur). Under that guarantee, describe (or write SQL for) how you would infer the final status as of2020-02-29using only the snapshot plus the multiset of February actions for each member.
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.