human
Check if a string is a scrambled form of another string | Python3 program to check if a given string is a scrambled form of another string.
Strings of non - equal length cant ' be scramble strings.
Empty strings are scramble strings.
Equal strings are scramble strings.
Check for the condition of anagram.
Check if S2 [ 0. . . i ] is a scrambled string of S1 [ 0. . . i ] and if S2 [ i + 1. . . n ] is a scrambled string of S1 [ i + 1. . . n ].
Check if S2 [ 0. . . i ] is a scrambled string of S1 [ n - i ... n ] and S2 [ i + 1. . . n ] is a scramble string of S1 [ 0. . . n - i - 1 ].
If none of the above conditions are satisfied.
Driver Code"
Solution in Python:
assistant
#Here is code to check if a string is a scrambled form of another string and the other steps required.
 def isScramble ( S1 : str , S2 : str ) :
	if len ( S1 ) != len ( S2 ) :
		return False
	n = len ( S1 )
	if not n :
		return True
	if S1 == S2 :
		return True
	if sorted ( S1 ) != sorted ( S2 ) :
		return False
	for i in range ( 1 , n ) :
		if ( isScramble ( S1 [ : i ] , S2 [ : i ] ) and isScramble ( S1 [ i : ] , S2 [ i : ] ) ) :
			return True
		if ( isScramble ( S1 [ - i : ] , S2 [ : i ] ) and isScramble ( S1 [ : - i ] , S2 [ i : ] ) ) :
			return True
	return False
if __name__ == " _ _ main _ _ " :
	S1 = " coder "
	S2 = " ocred "
	if ( isScramble ( S1 , S2 ) ) :
		print ( " Yes " )
	else :
		print ( " No " )