![]() |
VOOZH | about |
A string contains patterns of the form 1(0+)1 where (0+) represents any non-empty consecutive sequence of 0's. Count all such patterns. The patterns are allowed to overlap.
Note : It contains digits and lowercase characters only. The string is not necessarily a binary. 100201 is not a valid pattern.
One approach to solve the problem is discussed here, other using Regular expressions is given in Set 2
Examples:
Input : 1101001 Output : 2 Input : 100001abc101 Output : 2
Let size of input string be n.
Below is the implementation of the above method.
2
Time Complexity: O(n)
Auxiliary Space: O(1)