Given a binary string S of size N and an integer K. The task is to find the maximum number of set bit appears in a substring of size K.
Examples:
Input:_ S = “100111010”, K = 3_
Output:_ 3_
Explanation:
The substring “111” contains 3 set bits.
Input:S = “0000000”, K = 4
Output:_ 0_
Explanation:_ S doesn’t have any set bits in it, so ans is 0._
Naive Approach:
Time Complexity:_ O( N2)._
Auxillary Space:_ O(1)._
Efficient Approach: The problem can be solved using Sliding window technique.
#bit magic #strings #binary-string #setbitcount #sliding-window #substring