Longest Active Streak Allowing At Most K Missed Days
Last updated: November 29, 2026
Quick Overview
Given a sorted list of distinct day numbers on which a member was active and an integer k, return the length in days of the longest calendar span that contains at most k inactive days. The span must start and end on active days.
0
0
0 solved
Given a sorted list of distinct day numbers on which a member was active and an integer k, return the length in days of the longest calendar span that contains at most k inactive days. The span must start and end on active days.
LinkedIn tracks engagement streaks for features like Learning course goals and creator posting streaks. This screen question checks whether you can turn a 'forgiving streak' rule into a sliding window over sparse data instead of expanding every calendar day.
What the Interviewer Expects
- Recognizes the gaps inside a window are computable from endpoints
- Uses a two-pointer sliding window over the sorted active days
- Counts missed days as (span length) minus (active days in window)
- Handles k larger than any gap and an empty list
- Explains O(n) time without iterating calendar days
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
- What if the span is allowed to start or end on an inactive day?
- How would you answer this for every member nightly in a batch pipeline?
- What if days can repeat because events are logged multiple times per day?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Active days are sorted and distinct, for example [1,2,4,7,8]. For a window from active day days[i] to days[j], the span is days[j]-days[i]+1 days and the active count is j-i+1, so missed day...
High-Level Design
Missed days only grow as the right pointer advances and shrink as the left pointer advances, which is the monotonic property that makes a sliding window valid. Advance j; while the window has more t...