Check whether two strings contain same characters in same order | Python3 implementation of the approach ; string class has a constructor that allows us to specify the size of string as first parameter and character to be filled in given size as the second parameter . ; Function that returns true if the given strings contain same characters in same order ; Get the first character of both strings ; Now if there are adjacent similar character remove that character from s1 ; Now if there are adjacent similar character remove that character from s2 ; If both the strings are equal then return true ; Driver code
def getString ( x ) : NEW_LINE INDENT return x NEW_LINE DEDENT def solve ( s1 , s2 ) : NEW_LINE INDENT a = getString ( s1 [ 0 ] ) NEW_LINE b = getString ( s2 [ 0 ] ) NEW_LINE for i in range ( 1 , len ( s1 ) ) : NEW_LINE INDENT if s1 [ i ] != s1 [ i - 1 ] : NEW_LINE INDENT a += getString ( s1 [ i ] ) NEW_LINE DEDENT DEDENT for i in range ( 1 , len ( s2 ) ) : NEW_LINE INDENT if s2 [ i ] != s2 [ i - 1 ] : NEW_LINE INDENT b += getString ( s2 [ i ] ) NEW_LINE DEDENT DEDENT if a == b : NEW_LINE INDENT return True NEW_LINE DEDENT return False NEW_LINE DEDENT s1 = " Geeks " NEW_LINE s2 = " Geks " NEW_LINE if solve ( s1 , s2 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT