human
Find the longest sub | Z - algorithm function.
bit update function which updates values from index " idx " to last by value " val ".
Query function in bit.
Driver Code.
BIT array.
Making the z array.
update in the bit array from index z [ i ] by increment of 1.
if the value in z [ i ] is not equal to ( n - i ) then no need to move further.
queryng for the maximum length substring from bit array"
Solution in Python:
assistant
#Here is code to find the longest sub and the other steps required.
 def z_function ( s ) :
	global z , n
	n = len ( s )
	z = [ 0 ] * n
	l , r = 0 , 0
	for i in range ( 1 , n ) :
		if i <= r :
			z [ i ] = min ( r - i + 1 , z [ i - 1 ] )
		while ( i + z [ i ] < n and s [ z [ i ] ] == s [ i + z [ i ] ] ) :
			z [ i ] += 1
		if ( i + z [ i ] - 1 > r ) :
			l = i
			r = i + z [ i ] - 1
	return z
def update ( idx , val ) :
	global bit
	if idx == 0 :
		return
	while idx <= n :
		bit [ idx ] += val
		idx += ( idx & - idx )
def pref ( idx ) :
	global bit
	ans = 0
	while idx > 0 :
		ans += bit [ idx ]
		idx -= ( idx & - idx )
	return ans
if __name__ == " _ _ main _ _ " :
	n = 0
	length = 0
	bit = [ 0 ] * 1000005
	z = [ ]
	m = dict ( )
	s = " geeksisforgeeksinplatformgeeks "
	z = z_function ( s )
	for i in range ( 1 , n ) :
		update ( z [ i ] , 1 )
	for i in range ( n - 1 , 1 , - 1 ) :
		if z [ i ] != n - i :
			continue
		if ( pref ( n ) - pref ( z [ i ] - 1 ) ) >= 2 :
			length = max ( length , z [ i ] )
	if not length :
		print ( - 1 )
	else :
		print ( s [ : length ] )