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 of A and B.
  • All characters of A and B are present in C.
  • The order of characters is maintained as in A and B.

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!
Select
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?
TCS 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