Check if two array of string are equal by performing swapping operations | Function to check whether brr [ ] can be made equal to arr [ ] by doing swapping operations ; siz variable to store size 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
def checkEqualArrays ( arr , brr , N ) : NEW_LINE INDENT siz = len ( arr [ 0 ] ) ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT temp1 = list ( arr [ i ] ) ; NEW_LINE temp1 . sort ( ) ; NEW_LINE arr [ i ] = " " . join ( temp1 ) NEW_LINE temp2 = list ( brr [ i ] ) ; NEW_LINE temp2 . sort ( ) ; NEW_LINE brr [ i ] = " " . join ( temp2 ) ; NEW_LINE DEDENT arr . sort ( ) NEW_LINE brr . sort ( ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr [ i ] != brr [ i ] ) : NEW_LINE INDENT return False ; NEW_LINE DEDENT DEDENT return True ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 2 ; NEW_LINE arr = [ " bcd " , " aac " ] ; NEW_LINE brr = [ " aca " , " dbc " ] ; NEW_LINE ans = checkEqualArrays ( arr , brr , N ) ; NEW_LINE if ( ans ) : NEW_LINE INDENT print ( " true " ) ; NEW_LINE DEDENT else : NEW_LINE INDENT print ( " false " ) ; NEW_LINE DEDENT DEDENT