{"id":"3da6198f-f5df-4588-bb01-b5b9f9eeb7e9","name":"Scramble String","description":"1. You are given two strings s1 and s2.\r\n2. A string can be represented as a binary tree by partitioning it to two non-empty substrings recursively.\r\n3. If you choose any non-leaf node and swap its two children, then the string formed is the scramble of the original string.\r\n4. You have to determine if s2 is a scrambled string of s1.\r\n<img src=\"http://pepcoding.com/resources/ojquestionresource/images/scramblestring.jpeg\" style=\"width:550px\">","inputFormat":"2 strings s1 and s2","outputFormat":"Check the sample output and question video.","constraints":"1 &lt; length of strings &lt;= 100","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static boolean isScrambleTab(String s1, String s2) {\r\n\t\t//write your code here\r\n\t\t\r\n\t\treturn false;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString s1 = scn.next();\r\n\t\tString s2 = scn.next();\r\n\t\tSystem.out.println(isScrambleTab(s1,s2));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"great\r\nrgeat","sampleOutput":"true\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"6bd6ef1e-10cc-401d-abd6-d1ee34798150","name":"Scramble String","slug":"scramble-string","type":1}],"next":{"id":"165db049-cf9c-4320-9119-f9b362b7f686","name":"SCRAMBLE STRING MCQ","type":0,"slug":"scramble-string-mcq"},"prev":{"id":"2155c70b-97a1-427e-9ace-1c6b430fe44c","name":"Cherry Pickup","type":3,"slug":"cherry-pickup"}}}

Scramble String

1. You are given two strings s1 and s2. 2. A string can be represented as a binary tree by partitioning it to two non-empty substrings recursively. 3. If you choose any non-leaf node and swap its two children, then the string formed is the scramble of the original string. 4. You have to determine if s2 is a scrambled string of s1. <img src="http://pepcoding.com/resources/ojquestionresource/images/scramblestring.jpeg" style="width:550px">

{"id":"3da6198f-f5df-4588-bb01-b5b9f9eeb7e9","name":"Scramble String","description":"1. You are given two strings s1 and s2.\r\n2. A string can be represented as a binary tree by partitioning it to two non-empty substrings recursively.\r\n3. If you choose any non-leaf node and swap its two children, then the string formed is the scramble of the original string.\r\n4. You have to determine if s2 is a scrambled string of s1.\r\n<img src=\"http://pepcoding.com/resources/ojquestionresource/images/scramblestring.jpeg\" style=\"width:550px\">","inputFormat":"2 strings s1 and s2","outputFormat":"Check the sample output and question video.","constraints":"1 &lt; length of strings &lt;= 100","sampleCode":{"cpp":{"code":""},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static boolean isScrambleTab(String s1, String s2) {\r\n\t\t//write your code here\r\n\t\t\r\n\t\treturn false;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tString s1 = scn.next();\r\n\t\tString s2 = scn.next();\r\n\t\tSystem.out.println(isScrambleTab(s1,s2));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"great\r\nrgeat","sampleOutput":"true\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"6bd6ef1e-10cc-401d-abd6-d1ee34798150","name":"Scramble String","slug":"scramble-string","type":1}],"next":{"id":"165db049-cf9c-4320-9119-f9b362b7f686","name":"SCRAMBLE STRING MCQ","type":0,"slug":"scramble-string-mcq"},"prev":{"id":"2155c70b-97a1-427e-9ace-1c6b430fe44c","name":"Cherry Pickup","type":3,"slug":"cherry-pickup"}}}
plane

Editor


Loading...

Scramble String

hard

1. You are given two strings s1 and s2. 2. A string can be represented as a binary tree by partitioning it to two non-empty substrings recursively. 3. If you choose any non-leaf node and swap its two children, then the string formed is the scramble of the original string. 4. You have to determine if s2 is a scrambled string of s1.

Constraints

1 < length of strings <= 100

Format

Input

2 strings s1 and s2

Output

Check the sample output and question video.

Example

Sample Input

great rgeat

Sample Output

true

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode