Check if two array of string are equal by performing swapping operations | C ++ program for above approach ; Function to check whether brr [ ] can be made equal to arr [ ] by doing swapping operations ; siz variable to store siz of string ; iterate till N to sort strings ; sort each string in arr [ ] ; sort each string in brr [ ] ; Sort both the vectors so that all the comparable strings will be arranged ; iterate till N to compare string in arr [ ] and brr [ ] ; Compare each string ; Return false becaues if atleast one string is not equal then brr [ ] cannot be converted to arr [ ] ; All the strings are compared so at last return true . ; Driver code ; Store the answer in variable
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkEqualArrays ( vector < string > arr , vector < string > brr , int N ) { int siz = arr [ 0 ] . size ( ) ; for ( int i = 0 ; i < N ; i ++ ) { sort ( arr [ i ] . begin ( ) , arr [ i ] . end ( ) ) ; sort ( brr [ i ] . begin ( ) , brr [ i ] . end ( ) ) ; } sort ( arr . begin ( ) , arr . end ( ) ) ; sort ( brr . begin ( ) , brr . end ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] != brr [ i ] ) { return false ; } } return true ; } int main ( ) { int N = 2 ; vector < string > arr = { " bcd " , " aac " } ; vector < string > brr = { " aca " , " dbc " } ; bool ans = checkEqualArrays ( arr , brr , N ) ; if ( ans ) cout << " true " ; else cout << " false " ; return 0 ; }