Stadium Traffic Gaps

ASKED IN INTERVIEW
10pts
Classic

Problem Statement

Identify sequences of 3 or more consecutive days where the stadium had 100 or more visitors.

Rules:

  • Output columns: id, visit_date, people.
  • Condition: people >= 100 for at least 3 days in a row.
  • Sort by visit_date ascending.
Tests your understanding of
Window Functions, Gaps and Islands and Lead/Lag

Input Tables

stadium
id(INTEGER)visit_date(DATE)people(INTEGER)
12024-01-0110
22024-01-02109
32024-01-03150
42024-01-0499
52024-01-05145
62024-01-061455
72024-01-07199
82024-01-08188
stadium_events
event_id(INTEGER)id(INTEGER)event_name(VARCHAR)
5016Final Cup
weather_logs
id(INTEGER)temp(INTEGER)condition(VARCHAR)
172Sunny

Expected Output

id(INTEGER)visit_date(DATE)people(INTEGER)
52024-01-05145
62024-01-061455
72024-01-07199
82024-01-08188

Tags

HardASKED IN INTERVIEWWindow FunctionsGaps and IslandsLead/Lag
30-40 min
44%

Hints