← Flatiron Health Interview Insights
First, deduplicate events to one row per user per active day, then use the 'date minus row_number' trick to assign a group ID to consecutive active days. Within each group, compute the streak length and start/end dates, filter for streaks of at least 3 days, and finally select the first such streak per user whose end date falls within the specified 7-day window.
Pro tip: Always clarify whether the 7-day window is inclusive and whether 'first' means earliest start date or earliest end date; also confirm if the streak must be exactly 3 days or at least 3 days, as this changes the logic.
Use a subquery or CTE to select distinct user_id and event_date from the events table, ensuring one row per user per active day.
For each user, assign a row number ordered by date and compute date minus row_number (or equivalent) to create a group identifier for consecutive active days.
Group by user_id and the group identifier, then calculate the minimum date as streak_start, maximum date as streak_end, and count as streak_length.
Filter for streak_length >= 3 and streak_end within the 7-day window, then use ROW_NUMBER() partitioned by user_id ordered by streak_start (or streak_end) to get the first streak per user.
Return user_id, streak_start_date, and streak_end_date for the first qualifying streak per user.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Start by aggregating raw event data to daily counts of active users and revenue, then use window functions to compute the 7-day trailing average of DAU and the revenue per active user with NULLIF to avoid division by zero. Ensure the final output includes all calendar days in the range, even those with zero activity, by generating a date spine and left joining the aggregates.
Pro tip: When computing trailing averages, specify ROWS BETWEEN 6 PRECEDING AND CURRENT ROW to get exactly 7 days, and use NULLIF(DAU, 0) to return NULL for revenue per active user when DAU is zero, as required.
Create a series of all calendar days in the given range to ensure no days are missing, even if there was no activity.
From the raw event data, compute daily active users (distinct user count) and daily revenue (sum of revenue) for each day.
Left join the daily aggregates to the date spine, replacing NULLs with 0 for DAU and revenue to handle days with no activity.
Use a window function to calculate the 7-day trailing average of DAU, and compute revenue per active user with NULLIF to handle division by zero.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Use a window function to find the next event date after each order, then filter for gaps of exactly 10 days. For each user, select the earliest qualifying gap by ordering by order date and using ROW_NUMBER.
Pro tip: Clarify whether 'strict 10-day gap' means exactly 10 days or at least 10 days, and whether the post-gap event can be any event type. Also, consider edge cases like multiple orders on the same day.
Extract all orders and all events per user, ensuring proper ordering by date. Use a window function like LEAD to find the next event date after each order.
Calculate the difference in days between the order date and the next event date. Filter for gaps equal to 10 days (or as defined).
For each user, rank the qualifying gaps by order date and pick the earliest using ROW_NUMBER or a subquery with MIN.
Output user_id, order date, gap length, and first post-gap event date. Ensure the result is deduplicated per user.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.