You are given two strings word1 and word2. Merge them by adding letters in alternating order, starting with word1. If one string is longer than the other, append the additional letters onto the end of the merged string. Return the merged string.
You are given two strings word1 and word2. Merge them by adding letters in alternating order, starting with word1. If one string is longer than the other, append the additional letters onto the end of the merged string. Return the merged string.
Example 1:
Input: {"word1":"ab","word2":"pqrs"}
Output: apbqrs
Constraints:
1 <= word1.length, word2.length <= 100
word1 and word2 consist of lowercase English letters.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"word1":"ab","word2":"pqrs"}
One index i walks both words together. Each round takes word1[i] then word2[i], skipping a word once it has run out.