text: Minimum steps for increasing and decreasing Array to reach either 0 or N | Java 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 ; Print the minimum steps ; Driver Code ; Given N ; Given increasing and decreasing array ; Function call
code: import java . util . * ; public class GFG { public static void minSteps ( int N , int [ ] increasing , int [ ] decreasing ) { int min = Integer . MAX_VALUE ; for ( int i : increasing ) { if ( min > i ) min = i ; } int max = Integer . MIN_VALUE ; for ( int i : decreasing ) { if ( max < i ) max = i ; } int minSteps = Math . max ( max , N - min ) ; System . out . println ( minSteps ) ; } public static void main ( String [ ] args ) { int N = 7 ; int increasing [ ] = { 3 , 5 } ; int decreasing [ ] = { 6 } ; minSteps ( N , increasing , decreasing ) ; } }