Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Sliding Window Max Sum

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

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.

You need to log in / sign up to run or submit.

Problem

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.

Output

  1. One row per driver, with driver_id, max_window_sum, window_start_date, and window_end_date.
  2. Include only complete three-day windows within each driver's recorded date range.
  3. Order by driver_id ascending.

Schema

driver_daily_earnings
ColumnTypeDescription
earning_idPKINTUnique earnings record identifier
driver_idINTIdentifier of the DoorDash driver
earning_dateDATECalendar date of the driver's earnings
earningsDECIMAL(10,2)Driver earnings recorded for the date
Tablesdriver_daily_earnings
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results