Description

You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. Append remaining letters of the longer string.

Examples

Input:word1 = "abc", word2 = "pqr"
Output:"apbqcr"
Explanation:

Alternate characters.

Input:word1 = "hello", word2 = "world"
Output:hweolrllod
Explanation:

Take alternating characters: h(ello) + w(orld) = hw, then e(llo) + o(rld) = eo, then l(lo) + r(ld) = lr, then l(o) + l(d) = ll, then o + d = od. Result: hweolrllod

Input:word1 = "cat", word2 = "d"
Output:cdat
Explanation:

When one string is shorter, alternate until the shorter string is exhausted, then append remaining characters from the longer string: c + d = cd, then append remaining 'at' from word1.

Constraints

  • 1 ≤ word1.length, word2.length ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!