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
function inverseEqual ( arr , n ) { var brr = Array ( n ) . fill ( 0 ) ; for ( var i = 0 ; i < n ; i ++ ) { var present_index = arr [ i ] - 1 ; brr [ present_index ] = i + 1 ; } for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != brr [ i ] ) { document . write ( " " ) ; return ; } } document . write ( " " ) ; } var n = 4 ; var arr = [ 1 , 4 , 3 , 2 ] ; inverseEqual ( arr , n ) ;