Check whether the string S1 can be made equal to S2 with the given operation | Function to return the string formed by the odd indexed characters of s ; Function to return the string formed by the even indexed characters of s ; Function that returns true if s1 can be made equal to s2 with the given operation ; Get the string formed by the even indexed characters of s1 ; Get the string formed by the even indexed characters of s2 ; Get the string formed by the odd indexed characters of s1 ; Get the string formed by the odd indexed characters of s2 ; Sorting all the lists ; If the strings can be made equal ; Driver code
def partOdd ( s ) : NEW_LINE INDENT odd = [ ] NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if i % 2 != 0 : NEW_LINE INDENT odd . append ( s [ i ] ) NEW_LINE DEDENT DEDENT return odd NEW_LINE DEDENT def partEven ( s ) : NEW_LINE INDENT even = [ ] NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if i % 2 == 0 : NEW_LINE INDENT even . append ( s [ i ] ) NEW_LINE DEDENT DEDENT return even NEW_LINE DEDENT def canBeMadeEqual ( s1 , s2 ) : NEW_LINE INDENT even_s1 = partEven ( s1 ) NEW_LINE even_s2 = partEven ( s2 ) NEW_LINE odd_s1 = partOdd ( s1 ) NEW_LINE odd_s2 = partOdd ( s2 ) NEW_LINE even_s1 . sort ( ) NEW_LINE even_s2 . sort ( ) NEW_LINE odd_s1 . sort ( ) NEW_LINE odd_s2 . sort ( ) NEW_LINE if even_s1 == even_s2 and odd_s1 == odd_s2 : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT s1 = " cdab " NEW_LINE s2 = " abcd " NEW_LINE if canBeMadeEqual ( s1 , s2 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT