

Else if the value of the boolean variable scramble is equal to the false then print "No".įor solving this problem, first of all, we try to check a few things. Finally, check If the value of the boolean variable scramble is equal to the true then print "Yes".ġ0. After that, traverse from 0 to the length of the string and make a recursive call to the function itself for all the possible index combinations of the first string and the second string and store the result of the recursive calls in the boolean variable scramble.ĩ. Else create a variable scramble of the boolean type and initialize it as false.Ĩ. Check again if the first string is not equal to the second string, return false.ħ. Similarly, sort the second string using the inbuilt sort function.Ħ. After that, sort the first string using the inbuilt sort function.ĥ. Check if the first string is equal to the second string, return true.Ĥ. Create a function to check is the second string is the scrambled string of first string which accepts two string variables as it's a parameter.ģ. Initialize the two string variables s1 and s2 of the same size.Ģ.

s1 = "abcde"Īlgorithm for Scramble String Problem 1. Example s1 = "great"Įxplanation: As shown above in the images, we can see scrambling “great” results in “great”. Therefore “rgeat” is a scrambled string of original string i.e. This string can be scrambled by choosing any non leaf node and swapping it’s children. Representation of s as binary tree by recursively dividing it into two non-empty sub-strings. Check if the second string is a scrambled string of first one or not? Explanation “Scramble String” problem states that you are given two strings.
