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.

LinkedIn
Coding & Algorithms
Software Engineer
LinkedIn
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

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
sliding window
two pointers
sparse arrays
streak metrics
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported