human
Maximum segment value after putting k breakpoints in a number | Function to Find Maximum Number.
Maximum segment length.
Find value of first segment of seg_len.
Find value of remaining segments using sliding window.
To find value of current segment , first remove leading digit from previous value.
Then add trailing digit.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to maximum segment value after putting k breakpoints in a number and the other steps required.
 def findMaxSegment ( s , k ) :
	seg_len = len ( s ) - k
	res = 0
	for i in range ( seg_len ) :
		res = res * 10 + ( ord ( s [ i ] ) - ord ( '0' ) )
	seg_len_pow = pow ( 10 , seg_len - 1 )
	curr_val = res
	for i in range ( 1 , len ( s ) - seg_len ) :
		curr_val = curr_val - ( ord ( s [ i - 1 ] ) - ord ( '0' ) ) * seg_len_pow
		curr_val = ( curr_val * 10 + ( ord ( s [ i + seg_len - 1 ] ) - ord ( '0' ) ) )
		res = max ( res , curr_val )
	return res
if __name__ == ' _ _ main _ _ ' :
	s = "8754"
	k = 2
	print ( " Maximum ▁ number ▁ = ▁ " , findMaxSegment ( s , k ) )