Check if the given array is same as its inverse permutation | Java program to implement the above approach ; 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
import java . util . * ; class GFG { static void inverseEqual ( int arr [ ] , int n ) { int [ ] brr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { int present_index = arr [ i ] - 1 ; brr [ present_index ] = i + 1 ; } for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] != brr [ i ] ) { System . out . println ( " No " ) ; return ; } } System . out . println ( " Yes " ) ; } public static void main ( String [ ] args ) { int n = 4 ; int [ ] arr = { 1 , 4 , 3 , 2 } ; inverseEqual ( arr , n ) ; } }