Longest Run Of Consecutive Paid Months Per Patron
Last updated: November 29, 2026
Quick Overview
Given (patron_id, 'YYYY-MM') records of successful membership payments, possibly unsorted and with duplicates, return each patron's longest streak of consecutive paid months.
Patreon
November 29, 20260
0
0 solved
Given (patron_id, 'YYYY-MM') records of successful membership payments, possibly unsorted and with duplicates, return each patron's longest streak of consecutive paid months.
Patreon surfaces membership length to creators and can unlock loyalty perks after N months. This screen-style question checks clean grouping, date normalization across year boundaries, and a linear-time streak scan.
What the Interviewer Expects
- Normalizes year and month into a single month index so December to January is consecutive
- Deduplicates repeated payments in the same month
- Uses a set and only starts counting at the beginning of a run for O(n) time
- Returns a result for every patron seen
- Discusses what counts as a payment (refunded months, comped months)
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you allow one missed month as a grace period without breaking the streak?
- How would you compute the current streak as of a given month instead of the longest?
- Annual members pay once a year. How do you represent them in this model?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Each record is a successful charge for a given billing month. Multiple charges in a month (for example an upgrade) count once. Output a dict patron_id -> longest streak length....
High-Level Design
Convert YYYY-MM to year * 12 + (month - 1) so consecutive months differ by exactly one, including across a year boundary. Group into a set per patron. For each month index whose predecessor is not...