Python Interview Prep/Rolling Order Volume
DoorDash logo

Rolling Order Volume

DoorDash·hard·pandas·About 30 min in the room

orders has one row per delivery: order_id, city and order_date (text). For each city, and for every day from that city's first order to its last, find the number of orders and the 7-day rolling average of daily orders (that day and the six before it), rounded to 2 decimals. A day with no orders counts as 0 and still counts toward the window. Near the start, a window that does not have seven days yet averages the days it has. Return result with the columns city, order_date (YYYY-MM-DD), orders and rolling_7d, sorted by city, then date.

The data

orders22 rows
order_idint64cityobjectorder_dateobject
9001Denver2025-06-07
9002Denver2025-06-07
9003Austin2025-06-01
9004Austin2025-06-02
9005Austin2025-06-05
9006Austin2025-06-09
and 16 more rows

Target output

cityorder_dateordersrolling_7d
Austin2025-06-0133
Austin2025-06-0212
Austin2025-06-0301.33
Austin2025-06-0421.5
Austin2025-06-0542
Austin2025-06-0601.67
Austin2025-06-0701.43
Austin2025-06-0811.14
Austin2025-06-0921.29
Denver2025-06-0222
Denver2025-06-0322
Denver2025-06-0401.33
Denver2025-06-0501
Denver2025-06-0600.8
Denver2025-06-0751.5

What this question tests

Tests the difference between rows and days. A rolling window over rows treats the day after a gap as if it were the day before, so a 7-day average built that way quietly covers 9 or 10 days. Filling the missing days with zeros first is the whole question.

More Python interview questions

  • Weeks at Number One · Spotify · easy
  • The Salary Gap · LinkedIn · easy
  • Month-over-Month Revenue · Amazon · medium
  • Back Within a Week · Amazon · medium
Python
Shift+EnterPython is starting in your browser...
Output

Starting Python...