Scramble StringSelect any random index and split the string into two non-empty substrings. For e.g: if the string is ‘S’, then divide it into two non-empty substrings ‘A’ and ‘B’ such that ‘S’ = ‘A’ + ‘B’.
You can choose to swap the two substrings or keep them in the same order, i.e., after this operation string ‘S’ may become either ‘S’ = ‘A’ + ‘B’ or ‘S’ = ‘B’ + ‘A’.
Apply the first step recursively on each of the two strings ‘A’ and ‘B’.
You are given an integer ‘N’ and two strings ‘S’ and 'R' each having size = ‘N’. You can scramble the string ‘S’ to obtain string 'R' using the following operations:
1. If the length of the string is greater than 1:
2. If the length of the string is equal to 1 then stop.
Your task is to return true if 'R' is a scrambled string of ‘S’ else return false.
Note:
1. Both the strings are non-empty and are of the same length.
2. You can apply the above operations any number of times on ‘S’.
3. The operations can only be applied on the string ‘S’.
4. ‘S’ and 'R' consist of lowercase letters only.
Input Format:
The first line of the input contains an integer 'T' denoting the number of test cases.
The first line of each test case contains an integer ‘N’, denoting the size of the strings.
The second line of each test case contains two space-separated strings ‘S’ and 'R'.
Output Format:
For each test case print a single line containing either “true” if the string 'R' is a scrambled string of ‘S’, else “false”.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 50
1 <= len(S) <= 30
Where ‘len(S)’ represents the length of the string ‘S’.
Time Limit: 1 sec
Be the first one to answer
Add answer anonymously...
Top RUBRIK INDIA Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
>
RUBRIK INDIA Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app