Dsa
Sliding Window
Easy
The Reliable Broadcast
A radio station transmits a sequence of bits where 0 represents a 'clean' signal and 1 represents a 'distorted' signal. You need to find the longest continuous sequence of bits that is 'stable'. A sequence is stable if: 1) It contains at most K distorted signals (1s), and 2) It contains no two distorted signals (1s) that are adjacent to each other. Output the length of the longest stable sequence.
Example:
Input:
6 2
0 1 0 1 0 1
Output:
5
Explanation: K=2. The sequence [0, 1, 0, 1, 0] has two 1s and none are adjacent. Length 5.
Key concepts
sliding_windowlogic
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now