Time-Decayed Engagement Score per User with a Seven-Day Half-Life

Last updated: November 29, 2026

Quick Overview

Given daily interaction counts per user, compute an engagement score where each day's interactions decay with a seven-day half-life, both as of a chosen date and as a daily series, and rank users by score.

Meta
Data Manipulation (SQL/Python)
Machine Learning Engineer
Meta
November 29, 2026
Machine Learning Engineer
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given daily interaction counts per user, compute an engagement score where each day's interactions decay with a seven-day half-life, both as of a chosen date and as a daily series, and rank users by score.

Feed and notification ranking at Meta use recency-weighted engagement features, and MLE screens ask candidates to build one cleanly in pandas. The interviewer checks that inactivity correctly decays the score and that the recurrence handles irregular gaps between active days.

What the Interviewer Expects
  • Writes the score as a sum of actions times 0.5 to the power of age over half-life
  • Computes the as-of score with vectorized weights
  • Builds the daily series with the recurrence S_t = S_prev times decay(gap) plus x_t
  • Handles irregular gaps without densifying
  • Explains why pandas ewm (a weighted mean) is not the same as a decayed sum
Key Topics to Cover
exponential decay
half-life
recurrence over gaps
pandas groupby
feature engineering
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 compute this incrementally in a daily pipeline that only reads yesterday's score?
  • How would you choose the half-life for a notification-ranking feature?
  • How would you make the series vectorized for a billion user-days?
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

Input: user_id, ds, actions, sparse (only active days). Score definition:

S(t)=∑d≤tad⋅0.5(t−d)/h,h=7S(t) = \sum_{d \le t} a_d \cdot 0.5^{(t-d)/h}, \quad h = 7

A user who stops interacting should see their score hal...

Approach

As-of score: filter to days at or before the as-of date, weight each row by 0.5age/h0.5^{age/h} and sum per user. Daily series: the decayed sum satisfies Si=Si−1⋅0.5gapi/h+aiS_i = S_{i-1} \cdot 0.5^{gap_i/h} + a_i, so sort b...


Submit Your Answer
Markdown supported