human
Find the longest common prefix between two strings after performing swaps on second string | Python program to find the longest common prefix between two strings after performing swaps on the second string.
a = len ( x ) length of x b = len ( y ) length of y.
creating frequency array of characters of y.
storing the length of longest common prefix.
checking if the frequency of the character at position i in x in b is greater than zero or not if zero we increase the prefix count by 1.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to find the longest common prefix between two strings after performing swaps on second string and the other steps required.
 def LengthLCP ( x , y ) :
	fr = [ 0 ] * 26
	for i in range ( b ) :
		fr [ ord ( y [ i ] ) - 97 ] += 1
	c = 0
	for i in range ( a ) :
		if ( fr [ ord ( x [ i ] ) - 97 ] > 0 ) :
			c += 1
			fr [ ord ( x [ i ] ) - 97 ] -= 1
		else :
			break
	print ( c )
x , y = " here " , " there "
LengthLCP ( x , y )