Similar Strings Problem Statement
Determine whether two given strings, A
and B
, both of length N
, are similar by returning a 1 if they are, otherwise return a 0.
Explanation:
String A
is similar to string B
if the following conditions are met:
A
is equal toB
.- Both strings can be divided into two halves,
A1, A2
andB1, B2
, having equal lengths, such that at least one of the following is true:A1
is similar toB1
andA2
is similar toB2
.A1
is similar toB2
andA2
is similar toB1
.
Input:
The first line contains a single integer 'T'
, indicating the number of test cases.
For each test case, there are two space-separated strings: A
and B
.
Output:
For each test case, print 1
if 'A'
is similar to 'B'
, otherwise print 0
. Each result should be printed on a new line.
Example:
Input:
2
abcd dbca
abdc abcd
Output:
1
1
Constraints:
1 ≤ T ≤ 5
1 ≤ |A| = |B| ≤ 3000
- Both
A
andB
consist of only lowercase English letters. - Time limit: 1 second
Note:
You are not required to print anything; the task is to implement the given function and return the result.

AnswerBot
1y
The task is to determine if two strings are similar based on the given conditions.
Check if the strings are equal, if yes, return 1
Divide both strings into two parts and check if any combination satisf...read more
Help your peers!
Add answer anonymously...
>
Goldman Sachs Software Engineer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

