Minimum steps for increasing and decreasing Array to reach either 0 or N | Python3 program for the above approach ; Function that finds the minimum steps to reach either 0 or N for given increasing and decreasing arrays ; Initialize variable to find the minimum element ; Find minimum element in increasing array ; Initialize variable to find the maximum element ; Find maximum element in decreasing array ; Find the minimum steps ; Prthe minimum steps ; Driver Code ; Given N ; Given increasing and decreasing array ; Function call
import sys NEW_LINE def minSteps ( N , increasing , decreasing ) : NEW_LINE INDENT Min = sys . maxsize ; NEW_LINE for i in increasing : NEW_LINE INDENT if ( Min > i ) : NEW_LINE INDENT Min = i ; NEW_LINE DEDENT DEDENT Max = - sys . maxsize ; NEW_LINE for i in decreasing : NEW_LINE INDENT if ( Max < i ) : NEW_LINE INDENT Max = i ; NEW_LINE DEDENT DEDENT minSteps = max ( Max , N - Min ) ; NEW_LINE print ( minSteps ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 7 ; NEW_LINE increasing = [ 3 , 5 ] ; NEW_LINE decreasing = [ 6 ] ; NEW_LINE minSteps ( N , increasing , decreasing ) ; NEW_LINE DEDENT