Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Merge Strings Alternately

XPChallenge Points: 10
levelLevel: Easy

You are given two strings, word1 and word2. Your task is to create a new string by taking characters from each string one-by-one in alternating order, beginning with word1.

If one of the strings still has characters left after the alternating process ends, simply attach the remaining characters to the end of the result.

Return the newly formed string.

Example 1:

Input: word1 = "hello", word2 = "zz"

Output: "hzello"

Explanation:

Merge: h z e → remaining "llo" gets added.

Example 2:

Input: word1 = "xy", word2 = "1234"

Output: "x1y234"

Explanation:

Take x → 1 → y → 2, then leftover "34" is appended.

Example 3:

Input: word1 = "a", word2 = "b"

Output: "ab"

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result