Your question is Seven-Day Revenue Per User Average. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
On a Meta product such as Facebook, you are given raw daily monetization events and need to compute a smoothed revenue-per-user trend. Write a function that returns the 7-day rolling average of daily revenue per user (RPU) for each calendar day.
For each event, you are given a date string in YYYY-MM-DD format, a user_id, and a revenue amount. First aggregate events by day to compute:
daily revenue / daily active usersThen compute the 7-day rolling average of daily RPU over the current day and the previous 6 days. If fewer than 7 days exist so far, average over all available days.
Return a list of [date, rolling_average] pairs in ascending date order. Round each rolling average to 2 decimal places.
events, a list of lists where each item is [date, user_id, revenue][date, rolling_average]def rolling_rpu_7day(events):