FastPrepInterleave Two Strings

Interleave Two Strings

ZipRecruiter logoZipRecruiter● EasyNEW GRADOA
Learn

Problem statement

You are given two strings, first and second. Build a result by taking one character from first, then one from second, and repeating.

The first result character comes from first. When one string is exhausted, append the remaining suffix of the other string.

Function

interleaveStrings(first: String, second: String) → String

Examples

Example 1

first = "aaaaa"second = "bbb"return = "abababaa"

The first six characters alternate, then the two unused characters from the first string are appended.

Example 2

first = ""second = "abc"return = "abc"

The first string is empty, so the complete second string is appended.

Constraints

  • 0 <= first.length,second.length <= 100000
  • Both strings contain lowercase English letters.

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String interleaveStrings(String first, String second) {
    // Write your code here.
}
first"aaaaa"
second"bbb"
expected"abababaa"
Checking account…