Skip to content
Decoder

Interleaving String

Medium

Problem

Return true if s3 can be formed by interleaving s1 and s2: splitting both into pieces and merging the pieces so that each string's characters keep their original order. Every character of s1 and s2 must be used exactly once.

Example 1

Input
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"
Output
true

Example 2

Input
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"
Output
false

Example 3

Input
s1 = "", s2 = "", s3 = ""
Output
true

Constraints

  • 0 <= s1.length, s2.length <= 100
  • 0 <= s3.length <= 200
  • All strings contain only lowercase letters.

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.