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:

  1. A is equal to B.
  2. Both strings can be divided into two halves, A1, A2 and B1, B2, having equal lengths, such that at least one of the following is true:
    • A1 is similar to B1 and A2 is similar to B2.
    • A1 is similar to B2 and A2 is similar to B1.

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 and B 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!
Select
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.
Walmart Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits