Check if the given array is same as its inverse permutation | C ++ Program to implement the above approach ; Function to check if the inverse permutation of the given array is same as the original array ; Check the if inverse permutation is not same ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool inverseEqual ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) if ( arr [ arr [ i ] - 1 ] != i + 1 ) return false ; return true ; } int main ( ) { int n = 4 ; int arr [ n ] = { 1 , 4 , 3 , 2 } ; cout << ( inverseEqual ( arr , n ) ? " Yes " : " No " ) ; return 0 ; }