Tag Archives: binary-string

Count passing car pairs

A non-empty binary array A consisting of size N is given where, 0 represents a car traveling east, 1 represents a car traveling west. The goal is to count passing cars. We say that a pair of cars (P, Q), where 0

Length of Longest sub-string that can be removed

Given a binary string (consists of only 0 and 1). If there is “100” as a sub-string in the string, then we can delete this sub-string. The task is to find the length of longest sub-string which can be make removed? Examples: Input : str = “1011100000100” Output : 6 // Sub-strings present in str… Read More »

Generate all binary strings from given pattern

Given a string containing of ‘0’, ‘1’ and ‘?’ wildcard characters, generate all binary strings that can be formed by replacing each wildcard character by ‘0’ or ‘1’. Input str = “1??0?101” Output: 10000101 10001101 10100101 10101101 11000101 11001101 11100101 11101101 Method 1 (Using Recursion) We pass index of next character to the recursive function.… Read More »