Check if Array forms an increasing | Function to check if the given array forms an increasing decreasing sequence or vice versa ; Base Case ; First subarray is stricly increasing ; Check for strictly increasing condition & find the break point ; Check for strictly decreasing condition & find the break point ; If i is equal to length of array ; First subarray is strictly Decreasing ; Check for strictly increasing condition & find the break point ; Check for strictly increasing condition & find the break point ; If i is equal to length of array - 1 ; Condition if ar [ 0 ] == ar [ 1 ] ; Given array arr ; Function Call
def canMake ( n , ar ) : NEW_LINE INDENT if ( n == 1 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT else : NEW_LINE INDENT if ( ar [ 0 ] < ar [ 1 ] ) : NEW_LINE INDENT i = 1 ; NEW_LINE while ( i < n and ar [ i - 1 ] < ar [ i ] ) : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT while ( i + 1 < n and ar [ i ] > ar [ i + 1 ] ) : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT if ( i >= n - 1 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT else : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT elif ( ar [ 0 ] > ar [ 1 ] ) : NEW_LINE INDENT i = 1 ; NEW_LINE while ( i < n and ar [ i - 1 ] > ar [ i ] ) : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT while ( i + 1 < n and ar [ i ] < ar [ i + 1 ] ) : NEW_LINE INDENT i += 1 ; NEW_LINE DEDENT if ( i >= n - 1 ) : NEW_LINE INDENT return True ; NEW_LINE DEDENT else : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for i in range ( 2 , n ) : NEW_LINE INDENT if ( ar [ i - 1 ] <= ar [ i ] ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True ; NEW_LINE DEDENT DEDENT DEDENT arr = [ 1 , 2 , 3 , 4 , 5 ] ; NEW_LINE n = len ( arr ) ; NEW_LINE if ( canMake ( n , arr ) == False ) : NEW_LINE INDENT print ( " Yes " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) ; NEW_LINE DEDENT