Longest Consecutive-Day Posting Streak for Each Creator
Last updated: November 29, 2026
Quick Overview
From a posts table with creator_id and post timestamp, find each creator's longest run of consecutive calendar days with at least one post, returning the streak's start date, end date and length.
TikTok
November 29, 20260
0
0 solved
From a posts table with creator_id and post timestamp, find each creator's longest run of consecutive calendar days with at least one post, returning the streak's start date, end date and length.
Posting consistency feeds TikTok creator programs and in-app nudges that encourage daily posting. This classic gaps-and-islands question checks that you collapse multiple posts per day first, know the date minus row number trick, and break ties between equal streaks deliberately.
What the Interviewer Expects
- Collapse to distinct creator-days before numbering
- Use date minus ROW_NUMBER as a constant island key
- Aggregate each island to start, end and length
- Pick the longest streak with a stated tiebreaker
- Explain the timezone choice for what counts as a day
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 return each creator's current streak as of today instead of the longest ever?
- How would you allow one missed day without breaking the streak?
- How would you compute this incrementally each day instead of scanning all history?
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
posts(creator_id, post_ts)in UTC. Confirm whether a "day" is UTC or the creator's local day; for a creator-facing streak it should be local, which needs atimezonecolumn. I will assume the loc...
Approach
For consecutive dates, d - row_number is constant: Nov 1 minus 1, Nov 2 minus 2 and Nov 3 minus 3 all give Oct 31. A gap shifts the key. So:
- Distinct
(creator_id, day). - `grp_key = day - ROW_...