Your question is Sliding Window Max Sum. Start with the requirements and the one table 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.
Write a SQL query or algorithmic approach to calculate the maximum sum using a sliding window technique across daily driver earnings.
Use the driver_daily_earnings table and a three-calendar-day window. Treat missing dates and NULL earnings as zero. Return the earliest window when multiple windows have the same maximum.
driver_id, max_window_sum, window_start_date, and window_end_date.driver_id ascending.| Column | Type | Description |
|---|---|---|
| earning_idPK | INT | Unique earnings record identifier |
| driver_id | INT | Identifier of the DoorDash driver |
| earning_date | DATE | Calendar date of the driver's earnings |
| earnings | DECIMAL(10,2) | Driver earnings recorded for the date |