human
What is a code to longest prefix in a string with highest frequency and the other steps required given the following:
Longest prefix in a string with highest frequency | Function to find Longest prefix string with the highest frequency.
storing all indices where first element is found.
if the first letter in the string does not occur again then answer will be the whole string.
loop till second appearance of the first element.
check one letter after every stored index.
If there is no mismatch we move forward.
otherwise we stop.
Driver Code"
Solution in Python:
assistant
#Here is code to longest prefix in a string with highest frequency and the other steps required.
 def prefix ( string ) :
	k = 1 ;
	n = len ( string ) ;
	g = [ ] ;
	flag = 0 ;
	for i in range ( 1 , n ) :
		if ( string [ i ] == string [ 0 ] ) :
			g . append ( i ) ;
			flag = 1 ;
	if ( flag == 0 ) :
		print ( string ) ;
	else :
		length = len ( g ) ;
		while ( k < g [ 0 ] ) :
			cnt = 0 ;
			for j in range ( length ) :
				if ( string [ g [ j ] + k ] == string [ k ] ) :
					cnt += 1 ;
			if ( cnt == len ) :
				k += 1 ;
			else :
				break ;
		for i in range ( k + 1 ) :
			print ( string [ i ] , end = " " ) ;
		print ( )
if __name__ == " _ _ main _ _ " :
	string = " abcab " ;
	prefix ( string ) ;