Check if all disks can be placed at a single rod based on given conditions | Function to check if it is possible to move all disks to a single rod ; Stores if it is possible to move all disks to a single rod ; Traverse the array ; If i - th element is smaller than both its adjacent elements ; If flag is true ; Otherwise ; Driver Code
def check ( a , n ) : NEW_LINE INDENT flag = 0 NEW_LINE for i in range ( 1 , n - 1 ) : NEW_LINE INDENT if ( a [ i + 1 ] > a [ i ] and a [ i ] < a [ i - 1 ] ) : NEW_LINE INDENT flag = 1 NEW_LINE DEDENT DEDENT if ( flag != 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT else : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT arr = [ 1 , 3 , 5 , 2 ] NEW_LINE N = len ( arr ) NEW_LINE if ( check ( arr , N ) != 0 ) : NEW_LINE INDENT print ( " YES " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " NO " ) NEW_LINE DEDENT