Attribute Each Messenger Payment to the Session It Happened In

Last updated: November 29, 2026

Quick Overview

Given a Messenger sessions table with start and end times and a payments table with timestamps, attach each payment to the session that contains it, and report the share of payments made in sessions that began from a chat notification.

Meta
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given a Messenger sessions table with start and end times and a payments table with timestamps, attach each payment to the session that contains it, and report the share of payments made in sessions that began from a chat notification.

A range-join question in the style of Meta's data science technical screens. The interviewer checks a non-equi join between events and sessions, handling payments that fall outside every session, and preventing one payment from matching two overlapping sessions.

What the Interviewer Expects
  • Uses a range join on user and time between start and end
  • Keeps unmatched payments with a LEFT JOIN and reports them
  • Resolves overlaps so each payment maps to one session
  • Computes the share by entry point
  • Discusses join performance on large tables
Key Topics to Cover
range join
non-equi join
overlapping intervals
ROW_NUMBER
attribution
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you make the range join efficient at scale?
  • Why might many payments fall outside any session?
  • How would you compare payment rate per session across entry points fairly?
  • What changes if sessions are still open when the job runs?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

msgr_sessions(session_id, user_id, entry_point, start_ts, end_ts) and payments(payment_id, user_id, paid_ts, amount). A payment belongs to a session if start_ts <= paid_ts <= end_ts. Two devices...

Approach

Left join payments to sessions on user and the time range. Rank candidate sessions per payment by start time descending and keep rank 1 (or the NULL row). Then group by entry point, with COALESCE to...


Submit Your Answer
Markdown supported