Longest Consecutive Weekly Running Streak per Member in Pandas
Last updated: November 29, 2026
Quick Overview
Given a pandas DataFrame of runs (member_id, run_date, distance_km), compute each member's longest streak of consecutive calendar weeks (Monday start) that contain at least one run of at least 1 km, along with the week the streak started.
Nike
November 29, 20260
0
0 solved
Given a pandas DataFrame of runs (member_id, run_date, distance_km), compute each member's longest streak of consecutive calendar weeks (Monday start) that contain at least one run of at least 1 km, along with the week the streak started.
A Python data round in the style of Nike's consumer insights work on Nike Run Club, where weekly streaks drive retention features and badges. The interviewer is checking gaps-and-islands reasoning in pandas, week bucketing that does not break at year boundaries, and explicit tie handling.
What the Interviewer Expects
- Filters runs below the distance threshold before bucketing
- Buckets dates into Monday-start weeks with a continuous week index, not ISO week numbers that reset each year
- Deduplicates to one row per member-week
- Uses the index minus row-number trick (gaps and islands) instead of a Python loop
- States a tie rule and returns tidy output
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you compute each member's current streak as of today instead of their longest?
- Members are in many time zones. Which date should define a week?
- How would you do the same in SQL on a warehouse table with a billion runs?
- Product wants streaks to survive one missed week per quarter. How would you change the logic?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
One row per run, run_date is the member's local date, distance in km. A week runs Monday to Sunday. A week counts if it has any run of at least 1 km. Ties between equally long streaks resolve to the...
Approach
Compute week_start as the date minus its weekday, then a continuous integer week index (days since a fixed Monday, divided by 7). ISO week numbers reset in January and break streaks over New Year. A...