Longest Engagement Streak When Up to K Missed Days Are Forgiven

Last updated: November 29, 2026

Quick Overview

Given a binary array where 1 means the user was active that day and 0 means inactive, return the length of the longest contiguous run of days that contains at most k inactive days.

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

0

0

0 solved


Given a binary array where 1 means the user was active that day and 0 means inactive, return the length of the longest contiguous run of days that contains at most k inactive days.

Streaks drive engagement features across Meta apps, and the coding version is a sliding window with a constraint. Interviewers check that you shrink the window correctly and state why the window approach is linear.

What the Interviewer Expects
  • Uses a variable-size sliding window
  • Counts zeros inside the window and shrinks when above k
  • Updates the best length at the right moment
  • Explains the amortized O(n) bound
  • Handles k = 0 and k larger than the number of zeros
Key Topics to Cover
Sliding window
Two pointers
Arrays
Amortized analysis
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
  • Return the start and end day of the best streak.
  • Answer this for a stream of days with O(k) memory.
  • What if forgiving a day costs a variable amount and you have a budget?
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

Input: list of 0/1 and k >= 0. Output the maximum window length containing at most k zeros. O(n) time, O(1) space....

High-Level Design

Expand right one day at a time, incrementing zeros when the day is 0. While zeros > k, move left forward, decrementing zeros when a 0 leaves. After restoring the invariant, the window `[left...


Submit Your Answer
Markdown supported