Shuffle Two Strings Problem Statement

You are provided with three strings A, B, and C. The task is to determine if C is formed by interleaving A and B. C is considered an interleaving of A and B if:

  • The length of C equals the sum of the lengths of A and B.
  • All characters from A and B are present in C.
  • The order of characters from A and B is preserved in C.

Example:

Input:
A = "aab", B = "abc", C = "aaabbc"
Output:
True
Explanation:

C contains all characters of A and B in the same order as they appear in A and B, hence True.

Input:
A = "abc", B = "def", C = "abcdefg"
Output:
False
Explanation:

C is not an interleaving as it contains the character 'g', which isn't present in either A or B.

Input:

The first line contains an integer 'T,' 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. Results should be printed on separate lines for each test case.

Constraints:

  • 1 ≤ T ≤ 100
  • 1 ≤ |A|, |B| ≤ 1000
  • 1 ≤ |C| ≤ 2000
  • Strings A, B, and C contain only lowercase English letters.

Time limit: 1 second

AnswerBot
4mo

Check if a string is formed by interleaving two other strings.

  • Iterate through characters of A, B, and C simultaneously to check if C is formed by interleaving A and B.

  • Use dynamic programming to effici...read more

Help your peers!
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at Swiggy

Q. Subsequences of String Problem Statement You are provided with a string 'STR' th...read more
Q. Unique Binary Search Trees Problem Statement Given an integer 'N', your task is ...read more
Q. Count Ways To Travel Triangular Pyramid Bob is given a triangular pyramid with v...read more
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