169. Merge Strings Alternately

EasyStringString

You are given two strings word1 and word2. Merge them by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters to the end.

Return the merged string.

Input: Two comma-separated strings: word1 and word2.

Output: A single merged string.

Examples

Example 1
Input: abc,pqr
Output: apbqcr
Explanation: a+p, b+q, c+r → 'apbqcr'.
Example 2
Input: ab,pqrs
Output: apbqrs
Explanation: a+p, b+q, then 'rs' appended → 'apbqrs'.
Example 3
Input: abcd,pq
Output: apbqcd
Explanation: a+p, b+q, then 'cd' appended → 'apbqcd'.

Constraints

Asked by

GoogleMicrosoftAmazonMetaBloombergIBM
Solve this problem in the editor →