Shuffle Two Strings
You are provided with three strings: A
, B
, and C
. Your task is to determine if C
is formed by interleaving A
and B
. A string C
is considered an interleaving of A
and B
if:
- The length of
C
is equal to the sum of the lengths ofA
andB
. - All characters of
A
andB
are present inC
. - The order of characters is maintained as in
A
andB
.
Input:
The first line contains an integer 'T' representing the number of test cases. Each test case consists of a single line with three space-separated strings: A, B, and C.
Output:
For each test case, output 'True' if C is an interleaving of A and B, otherwise output 'False'. Each result should be printed on a new line.
Example:
Input:
A = "aab", B = "abc", C = "aaabbc"
Output:
True
Explanation:
C is an interleaving of A and B since it contains all characters of A and B in the correct order.
Input:
A = "abc", B = "def", C = "abcdefg"
Output:
False
Explanation:
C is not an interleaving of A and B because it includes an extra character 'g'.
Constraints:
- 1 <= T <= 100
- 1 <= |A|, |B| <= 1000
- 1 <= |C| <= 2000
- All characters in A, B, and C are lowercase English letters.
- Time limit: 1 second

AnswerBot
4mo
Determine if a string C is formed by interleaving two strings A and B.
Check if the length of C is equal to the sum of lengths of A and B.
Ensure all characters of A and B are present in C.
Verify that t...read more
Help your peers!
Add answer anonymously...
TCS Software Developer interview questions & answers
A Software Developer was asked 1w agoQ. What is Python?
A Software Developer was asked 3w agoQ. What is the process for synthesizing data to train a machine learning model with...read more
A Software Developer was asked 1mo agoQ. What is a string?
Popular interview questions of Software Developer
A Software Developer was asked 1w agoQ1. What is Python?
A Software Developer was asked 3w agoQ2. What is the process for synthesizing data to train a machine learning model with...read more
A Software Developer was asked 1mo agoQ3. What is a string?
Top HR questions asked in TCS Software Developer
A Software Developer was asked 5d agoQ1. Can you provide an explanation of your project?
A Software Developer was asked 2mo agoQ2. Why should we choose you?
A Software Developer was asked 2mo agoQ3. What are your hobbies?
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

