human
Check if a binary string has a 0 between 1 s or not | Set 1 ( General approach ) | Function returns 1 when string is valid else returns 0.
Find first occurrence of 1 in s [ ].
Find last occurrence of 1 in s [ ].
Check if there is any 0 in range.
Driver code"
Solution in Python:
assistant
#Here is code to check if a binary string has a 0 between 1 s or not and the other steps required.
 def checkString ( s ) :
	Len = len ( s )
	first = len ( s ) + 1
	for i in range ( Len ) :
		if ( s [ i ] == '1' ) :
			first = i
			break
	last = 0
	for i in range ( Len - 1 , - 1 , - 1 ) :
		if ( s [ i ] == '1' ) :
			last = i
			break
	for i in range ( first , last + 1 ) :
		if ( s [ i ] == '0' ) :
			return False
	return True
s = "00011111111100000"
if ( checkString ( s ) ) :
	print ( " VALID " )
else :
	print ( " NOT ▁ VALID " )