Given two strings word1 and word2, merge them by interleaving their characters in alternating order, beginning with the first character of word1. If one string is longer than the other, append the remaining characters of the longer string to the end of the merged result.
Return the resulting merged string.
Constraints:
word1.length, word2.length
word1 and word2 consist of lowercase English letters.
The key idea is to use two pointers to simultaneously traverse both input strings, picking one character at a time from each string in alternating fashion. We initialize one pointer for word1 and another for word2, both starting at index word1 followed by the character at the current position of word2 to a result list. Once one of the strings is fully traversed, we simply append all remaining characters ...
Given two strings word1 and word2, merge them by interleaving their characters in alternating order, beginning with the first character of word1. If one string is longer than the other, append the remaining characters of the longer string to the end of the merged result.
Return the resulting merged string.
Constraints:
word1.length, word2.length
word1 and word2 consist of lowercase English letters.
The key idea is to use two pointers to simultaneously traverse both input strings, picking one character at a time from each string in alternating fashion. We initialize one pointer for word1 and another for word2, both starting at index word1 followed by the character at the current position of word2 to a result list. Once one of the strings is fully traversed, we simply append all remaining characters ...