human
Remove all occurrences of a word from a given string using Z | Function to fill the Z - array for str.
L Stores start index of window which matches with prefix of str.
R Stores end index of window which matches with prefix of str.
Iterate over the characters of str.
If i is greater thn R.
Update L and R.
If substring match with prefix.
Update R.
Update Z [ i ].
Update R.
Update k.
if Z [ k ] is less than remaining interval.
Update Z [ i ].
Start from R and check manually.
Update R.
Update Z [ i ].
Update R.
Function to remove all the occurrences of word from str.
Create concatenated string " P $ T ".
Store Z array of concat.
Stores string , str by removing all the occurrences of word from str.
Stores length of word.
Traverse the array , Z [ ].
if Z [ i + pSize + 1 ] equal to length of word.
Update i.
Driver Code"
Solution in Python:
 Write me a code to remove all occurrences of a word from a given string using Z and the other steps required?
assistant
#Here is code to remove all occurrences of a word from a given string using Z and the other steps required.
 def getZarr ( st , Z ) :
	n = len ( st )
	k = 0
	L = 0
	R = 0
	for i in range ( 1 , n ) :
		if ( i > R ) :
			L = R = i
			while ( R < n and st [ R - L ] == st [ R ] ) :
				R += 1
			Z [ i ] = R - L
			R -= 1
		else :
			k = i - L
			if ( Z [ k ] < R - i + 1 ) :
				Z [ i ] = Z [ k ]
			else :
				L = i
				while ( R < n and st [ R - L ] == st [ R ] ) :
					R += 1
				Z [ i ] = R - L
				R -= 1
def goodStr ( st , word ) :
	concat = word + " $ " + st
	l = len ( concat )
	Z = [ 0 ] * l
	getZarr ( concat , Z )
	res = " "
	pSize = len ( word )
	for i in range ( l ) :
		if ( i + pSize < l - 1 and Z [ i + pSize + 1 ] == pSize ) :
			i += pSize - 1
		elif ( i < len ( st ) ) :
			res += st [ i ]
	return res
if __name__ == " _ _ main _ _ " :
	st = " Z - kmalgorithmkmiskmkmkmhelpfulkminkmsearching "
	word = " km "
	print ( goodStr ( st , word ) )