 New update is available. Click here to update.

# Rearranging String

Posted: 15 Mar, 2021
Difficulty: Moderate

## PROBLEM STATEMENT

#### If the length of the string is 1 then stop.

##### Example:
``````If ‘S’= “great” and ‘W’= “tagre”, ‘S’ can be rearranged to form ‘W’.

‘S’ = “gre” + “at” (We choose to swap ‘X’ & ‘Y’)
‘S’ = “at” + “gre”
Now letting “gre” as it is and applying operation on “at”.
‘S’ = “a” + “t” + “gre”
Swapping “a” and “t”
‘S’ = “t” + “a” + “gre”
Therefore ‘S’ can be rearranged into ‘W’.
``````
##### Note:
``````Both strings are of the same length and operations can only be applied to string ‘S’.
``````
##### Input Format:
``````The first line contains a single integer ‘T’ representing the number of test cases.

The first line of each test case contains a single integer ‘N’ denoting the length of the string ‘S’ and ‘W'.

The next line of the test case contains two space-separated strings ‘S’ and ‘W’.
``````
##### Output Format:
``````For each test case print ‘True’ if ‘S’ can be rearranged to form ‘W’ else print ‘False’.
``````
##### Note:
``````You do not need to print anything; it has already been taken care of. Just implement the function.
``````
##### Constraints:
``````1 <= T <= 50
1 <= N <= 20

Time Limit: 1sec
``````
SIMILAR PROBLEMS

DECODE STRING

Posted: 11 Sep, 2022
Difficulty: Moderate

Cakes

Posted: 23 Sep, 2022
Difficulty: Easy

1-3 Palindrome

Posted: 4 Oct, 2022
Difficulty: Easy

Randomly Sorted

Posted: 13 Nov, 2022
Difficulty: Moderate

8-Queen Problem

Posted: 19 Dec, 2022
Difficulty: Easy