human
What is a code to count of substrings whose Decimal equivalent is greater than or equal to K and the other steps required given the following:
Count of substrings whose Decimal equivalent is greater than or equal to K | Function to count number of substring whose decimal equivalent is greater than or equal to K.
Left pointer of the substring.
Right pointer of the substring.
Loop to maintain the last occurrence of the 1 in the string.
Variable to count the substring.
Loop to maintain the every possible end index of the substring.
Loop to find the substring whose decimal equivalent is greater than or equal to K.
Condition to check no of bits is out of bound.
Driver Code"
Solution in Python:
assistant
#Here is code to count of substrings whose Decimal equivalent is greater than or equal to K and the other steps required.
 def countSubstr ( s , k ) :
	n = len ( s )
	l = n - 1
	r = n - 1
	arr = [ 0 ] * n
	last_indexof1 = - 1
	for i in range ( n ) :
		if ( s [ i ] == '1' ) :
			arr [ i ] = i
			last_indexof1 = i
		else :
			arr [ i ] = last_indexof1
	no_of_substr = 0
	for r in range ( n - 1 , - 1 , - 1 ) :
		l = r
		while ( l >= 0 and ( r - l + 1 ) <= 64 and int ( s [ l : r + 1 ] , 2 ) < k ) :
			l -= 1
		if ( r - l + 1 <= 64 ) :
			no_of_substr += l + 1
		else :
			no_of_substr += arr [ l + 1 ] + 1
	return no_of_substr
s = "11100"
k = 3
print ( countSubstr ( s , k ) )