
Asked in Walmart
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...
Top Software Developer Interview Questions Asked at Walmart
Q. Tell me about yourself.
Q. How many languages do you know?
Q. What are your strengths?
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Walmart Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 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

