All-Time-High Follower Days and Drawdowns for Facebook Pages in Pandas

Last updated: November 29, 2026

Quick Overview

Given a daily follower count per Facebook Page in a pandas DataFrame, flag days that set a new all-time high, compute the drawdown from the running peak, and count days elapsed since the last high.

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 daily follower count per Facebook Page in a pandas DataFrame, flag days that set a new all-time high, compute the drawdown from the running peak, and count days elapsed since the last high.

Creator and Page analytics at Meta highlight milestones and declines, and Python screens often ask for cumulative window operations in pandas. The interviewer checks groupby with cummax and shift, a correct strictly-greater definition of a new high, and a run counter built from a cumulative sum.

What the Interviewer Expects
  • Sorts by page and date before any cumulative operation
  • Uses groupby cummax for the running peak
  • Compares with the previous day's peak via shift to define a new high
  • Computes drawdown as a fraction of the running peak
  • Builds a days-since-high counter with a cumsum run id
Key Topics to Cover
pandas cummax
groupby shift
running peak
run counter with cumsum
drawdown
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 find each Page's largest drawdown and how long it took to recover?
  • How would you handle missing days in the follower series?
  • How would you vectorize this for 100 million Page-days without a Python lambda?
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

DataFrame columns: page_id, ds (datetime), followers. One row per Page per day. A new high is strictly above every earlier day; matching the old peak does not count. The first day for each Page ...

Approach

Within each Page: cummax() gives the peak to date; shifting that by one gives the peak before today. A new high is the first day or followers above the previous peak. Drawdown is `(followers - peak)...


Submit Your Answer
Markdown supported

Related Questions