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
4mo
Determine if two strings are similar based on given conditions.
Check if the strings are equal first.
Then check if the strings can be divided into two halves with similar patterns.
Return 1 if the strin...read more
Help your peers!
Add answer anonymously...
Walmart Software Developer interview questions & answers
A Software Developer was asked 2mo agoQ. Why should we choose you?
A Software Developer was asked 2mo agoQ. Tell me about yourself.
A Software Developer was asked 4mo agoQ. Describe your experience with take-home projects involving API fetching.
Popular interview questions of Software Developer
A Software Developer was asked 2mo agoQ1. Why should we choose you?
A Software Developer was asked 2mo agoQ2. Tell me about yourself.
A Software Developer was asked 4mo agoQ3. Describe your experience with take-home projects involving API fetching.
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

