All tasks

Consecutive Doctor Visits (Consecutive Streak)

Advanced

Meta/Netflix level task. **Condition:** Find patients who visited the doctor at least 5 times in a row (in consecutive days or with no more than 7 days between visits). **Table:** appointments (patient_id, appointment_date, status, ...) **Requirements:** 1. Only consider completed appointments (status = 'completed') 2. Visits are considered consecutive if there are ≤ 7 days between them 3. Output patient_id, streak_start, streak_end, streak_length **Hint:** Gaps & Islands pattern — diff

Category
Window Functions
Estimated time
~25 min
Databases
PostgreSQLGreenplum
Tags
FAANGInterviewGaps & IslandsStreakROW_NUMBERоконные функции

Sign in to solve

Start Solving