The Human Traffic of Stadium coding problem is a database challenge. You are given a Stadium table with id, visit_date, and people. You need to find all rows where there are three or more consecutive rows with at least 100 people in each row. The output should be ordered by visit_date.
Uber and Meta use this "Hard" SQL problem to evaluate a candidate's ability to analyze sequential data in a relational database. It tests your proficiency with Window Functions or self-joins to identify groups of consecutive records. This is a common requirement in data analysis for identifying trends, streaks, or anomalous behaviors over time.
There are two main ways to solve this using Database interview patterns:
people >= 100.ROW_NUMBER() to generate a sequence.id - row_number will be the same for any consecutive sequence of IDs.COUNT(*) >= 3.Table Data:
| id | people |
|---|---|
| 1 | 50 |
| 2 | 150 |
| 3 | 200 |
| 4 | 120 |
| 5 | 80 |
Master the ROW_NUMBER() trick for finding consecutive sequences. It’s a very common pattern: val - ROW_NUMBER() OVER(ORDER BY val) creates a constant "group ID" for any sequence of consecutive values.