Check if the given array is same as its inverse permutation | Function to check if the inverse permutation of the given array is same as the original array ; Stores the inverse permutation ; Generate the inverse permutation ; Check if the inverse permutation is same as the given array ; Driver code
def inverseEqual ( arr , n ) : NEW_LINE INDENT brr = [ 0 ] * n NEW_LINE for i in range ( n ) : NEW_LINE INDENT present_index = arr [ i ] - 1 NEW_LINE brr [ present_index ] = i + 1 NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if arr [ i ] != brr [ i ] : NEW_LINE INDENT print ( " NO " ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( " YES " ) NEW_LINE DEDENT n = 4 NEW_LINE arr = [ 1 , 4 , 3 , 2 ] NEW_LINE inverseEqual ( arr , n ) NEW_LINE