![]() |
VOOZH | about |
Given a binary string S of length N, the task is to find the minimum number of characters required to be deleted from the string such that no subsequence of the form “0101” exists in the string.
Examples:
Input: S = "0101101"
Output: 2
Explanation: Removing S[1] and S[5] modifies the string to 00111. Therefore, no subsequence of the type 0101 can be obtained from the given string.Input: S = "0110100110"
Output: 2
Approach: Follow the steps below to solve the problem:
Below is the implementation of the above approach:
3
Time Complexity: O(N2)
Auxiliary Space: O(N)