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
Be the first one to answer
Add answer anonymously...
Top TCS Software Developer interview questions & answers
Popular interview questions of Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app