human
Longest substring consisting of vowels using Binary Search | Function to check if a character is vowel or not.
0 - a 1 - b 2 - c and so on 25 - z.
Function to check if any substring of length k exists which contains only vowels.
Applying sliding window to get all substrings of length K.
Remove the occurence of ( i - k + 1 ) th character.
Function to perform Binary Search.
Doing binary search on the lengths.
Driver Code"
Solution in Python:
 ... Can you provide a code to longest substring consisting of vowels using Binary Search and the other steps required?
assistant
#Here is code to longest substring consisting of vowels using Binary Search and the other steps required.
 def vowel ( vo ) :
	if ( vo == 0 or vo == 4 or vo == 8 or vo == 14 or vo == 20 ) :
		return True
	else :
		return False
def check ( s , k ) :
	cnt = [ 0 ] * 26
	for i in range ( k - 1 ) :
		cnt [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
	for i in range ( k - 1 , len ( s ) ) :
		cnt [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
		flag1 = 0
		for j in range ( 26 ) :
			if ( vowel ( j ) == False and cnt [ j ] > 0 ) :
				flag1 = 1
				break
		if ( flag1 == 0 ) :
			return True
		cnt [ ord ( s [ i - k + 1 ] ) - ord ( ' a ' ) ] -= 1
	return False
def longestSubstring ( s ) :
	l = 1
	r = len ( s )
	maxi = 0
	while ( l <= r ) :
		mid = ( l + r ) // 2
		if ( check ( s , mid ) ) :
			l = mid + 1
			maxi = max ( maxi , mid )
		else :
			r = mid - 1
	return maxi
if __name__ == " _ _ main _ _ " :
	s = " sedrewaefhoiu "
	print ( longestSubstring ( s ) )