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
November 29, 20260
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
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- 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 ProblemsSample 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)...