#190
Compress Consecutive Order Days
MEDIUMTime-series & PartitionsPOSTGRESQL
Problem Description
You are building a consumer ordering pattern compression pipeline for a food delivery platform. Given a table of raw consumer orders, collapse each consumer's activity timeline into consecutive date ranges — compressing multiple individual order days into compact `[start_date, end_date]` intervals.
**Range Rules:**
- Multiple orders on the same date by the same consumer count as a single active day
- Consecutive calendar dates (no gap between days) belong to the same date range
- A gap of 1 or more calendar days between active order days starts a new range
- A single isolated active day produces a range where `start_date = end_date`
Return `consumer_id`, `start_date`, `end_date` ordered by `consumer_id` ascending, `start_date` ascending.
Topics
window functionsaggregationdate arithmetic
Asked at Companies
doordash
Solve This Problem
Sign up to access the interactive code editor, run test cases, view the editorial, and get AI-powered feedback on your solution.
Start Solving →