human
Longest Common Prefix using Divide and Conquer Algorithm | A Utility Function to find the common prefix between strings - str1 and str2.
A Divide and Conquer based function to find the longest common prefix . This is similar to the merge sort technique.
Same as ( low + high ) / 2 , but avoids overflow for large low and high.
Driver Code"
Solution in Python:
 Give me a code to longest Common Prefix using Divide and Conquer Algorithm and the other steps required?
assistant
#Here is code to longest Common Prefix using Divide and Conquer Algorithm and the other steps required.
 def commonPrefixUtil ( str1 , str2 ) :
	result = " "
	n1 , n2 = len ( str1 ) , len ( str2 )
	i , j = 0 , 0
	while i <= n1 - 1 and j <= n2 - 1 :
		if str1 [ i ] != str2 [ j ] :
			break
		result += str1 [ i ]
		i , j = i + 1 , j + 1
	return result
def commonPrefix ( arr , low , high ) :
	if low == high :
		return arr [ low ]
	if high > low :
		mid = low + ( high - low ) // 2
		str1 = commonPrefix ( arr , low , mid )
		str2 = commonPrefix ( arr , mid + 1 , high )
		return commonPrefixUtil ( str1 , str2 )
if __name__ == " _ _ main _ _ " :
	arr = [ " geeksforgeeks " , " geeks " , " geek " , " geezer " ]
	n = len ( arr )
	ans = commonPrefix ( arr , 0 , n - 1 )
	if len ( ans ) :
		print ( " The ▁ longest ▁ common ▁ prefix ▁ is " , ans )
	else :
		print ( " There ▁ is ▁ no ▁ common ▁ prefix " )