human
Extract maximum numeric value from a given string | Set 1 ( General approach ) | Utility function to find maximum string.
If both having equal lengths.
Reach first unmatched character / value.
Return string with maximum value.
If different lengths return string with maximum length.
Function to extract the maximum value.
Start traversing the string.
Ignore leading zeroes.
Store numeric value into a string.
Update maximum string.
To handle the case if there is only 0 numeric value.
Return maximum string.
Driver Code"
Solution in Python:
assistant
#Here is code to extract maximum numeric value from a given string and the other steps required.
 def maximumNum ( curr_num , res ) :
	len1 = len ( curr_num ) ;
	len2 = len ( res ) ;
	if ( len1 == len2 ) :
		i = 0 ;
		while ( curr_num [ i ] == res [ i ] ) :
			i += 1 ;
		if ( curr_num [ i ] < res [ i ] ) :
			return res ;
		else :
			return curr_num ;
	return res if ( len1 < len2 ) else curr_num ;
def extractMaximum ( str ) :
	n = len ( str ) ;
	curr_num = " " ;
	res = " " ;
	for i in range ( n ) :
		while ( i < n and str [ i ] == '0' ) :
			i += 1 ;
		while ( i < n and str [ i ] >= '0' and str [ i ] <= '9' ) :
			curr_num += str [ i ] ;
			i += 1 ;
		if ( i == n ) :
			break ;
		if ( len ( curr_num ) > 0 ) :
			i -= 1 ;
		res = maximumNum ( curr_num , res ) ;
		curr_num = " " ;
	if ( len ( curr_num ) == 0 and len ( res ) == 0 ) :
		res += '0' ;
	return maximumNum ( curr_num , res ) ;
str = "100klh564abc365bg " ;
print ( extractMaximum ( str ) ) ;