Find Each Google Fit User's Longest Daily Step Goal Streak in Pandas
Last updated: November 29, 2026
Quick Overview
Given a DataFrame of daily step counts and step goals for Google Fit users, return each user's longest run of consecutive calendar days meeting their goal, with start and end dates.
0
0
0 solved
Given a DataFrame of daily step counts and step goals for Google Fit users, return each user's longest run of consecutive calendar days meeting their goal, with start and end dates.
A pandas gaps-and-islands problem in the style of Google's Python data rounds, set in Google Fit. The interviewer checks that a missing day breaks a streak, that you avoid Python loops over rows, and that users with no qualifying day still appear.
What the Interviewer Expects
- Filter to days that met the goal and sort by user and date
- Use the date minus a running position trick to label consecutive runs
- Treat missing calendar days as breaks
- Keep users with zero qualifying days in the output
- State a tie-break rule when two streaks have equal length
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 allow one missed day (a streak freeze) without breaking the streak?
- Dates are in UTC but users live in many time zones. What changes?
- How would you write this in SQL?
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
Columns user_id, date, steps, goal. I assume at most one row per user per day, but I will dedupe defensively. Dates are already in the user's local time. A streak is consecutive calendar days with `...
Approach
Classic gaps and islands. After filtering to qualifying days and sorting, cumcount() gives each row's position within the user. For consecutive dates, date - position days is constant, so that dif...