Median Daily Time Spent per User in Each Week on Facebook

Last updated: November 29, 2026

Quick Overview

From per-session time spent records, compute for each week the median across users of their average daily minutes on the Facebook app, counting only days the user was active. Report the 90th percentile as well.

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

0

0

0 solved


From per-session time spent records, compute for each week the median across users of their average daily minutes on the Facebook app, counting only days the user was active. Report the 90th percentile as well.

Time spent is a core Meta engagement metric, and this question tests whether you can do a two-level aggregation in the right order. The interviewer is watching for candidates who take a percentile over sessions instead of over users, which answers a different question.

What the Interviewer Expects
  • Aggregate sessions to user-day minutes first
  • Average to user-week over active days
  • Take the percentile across users per week
  • Use APPROX_PERCENTILE and explain why
  • Be explicit about the active-day denominator
Key Topics to Cover
two-level aggregation
percentiles
APPROX_PERCENTILE
time spent
weekly rollup
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 does the answer change if inactive days count as zero?
  • Why is the mean much higher than the median here?
  • How would you detect a logging change that inflates session length?
  • How would you compare iOS and Android fairly?
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

fb_sessions(user_id, session_start, duration_sec). A session is attributed to the day it starts (UTC). The metric is: for each user, average minutes per active day that week, then the median and p90...

Approach

Three grains: session to user-day (sum), user-day to user-week (average over active days), user-week to week (percentiles). Doing a percentile over sessions would describe sessions, and a percentile o...


Submit Your Answer
Markdown supported