Check if two arrays can be made equal by reversing subarrays multiple times | Java implementation to check if two arrays can be made equal ; Function to check if array B can be made equal to array A ; Sort both the arrays ; Check if both the arrays are equal or not ; Driver code
import java . util . * ; class GFG { public static boolean canMadeEqual ( int [ ] A , int [ ] B , int n ) { Arrays . sort ( A ) ; Arrays . sort ( B ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( A [ i ] != B [ i ] ) { return false ; } } return true ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 2 , 3 } ; int B [ ] = { 1 , 3 , 2 } ; int n = A . length ; if ( canMadeEqual ( A , B , n ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }