Dsa
Backtracking
Medium
Balanced Bit Window
Given a string of length N consisting of '0', '1', and '?', and two integers K and C, replace every '?' with either '0' or '1' such that in every sliding window of size K, the number of '1's is exactly C. Print the lexicographically smallest valid string, or 'None' if no such string exists.
Example:
Input:
4 2 1
??1?
Output:
1010
(Explanation: Windows of size 2 are (1,0) and (0,1) and (1,0). All have one '1'.)
Key concepts
backtrackingsliding windowstrings
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