Check if two arrays can be made equal by reversing subarrays multiple times | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool canMadeEqual ( int A [ ] , int B [ ] , int n ) { sort ( A , A + n ) ; sort ( B , B + n ) ; for ( int i = 0 ; i < n ; i ++ ) if ( A [ i ] != B [ i ] ) return false ; return true ; } int main ( ) { int A [ ] = { 1 , 2 , 3 } ; int B [ ] = { 1 , 3 , 2 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; if ( canMadeEqual ( A , B , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }