Build a new string by taking characters alternately from two input strings.
Given two strings, construct a new string by alternating characters from the first and second strings, starting with the first string.
Return the merged string.
This is a straightforward string-building problem that tests careful indexing and simulation.
word1 and word2.word1 and word2.Example 1
Input
word1 = "abc", word2 = "pqr"
Output
"apbqcr"
Explanation
Take a from word1, p from word2, b from word1, q from word2, c from word1, r from word2.
Example 2
Input
word1 = "ab", word2 = "pqrs"
Output
"apbqrs"
Explanation
Alternate until word1 ends, then append the remaining characters from word2.
Example 3
Input
word1 = "abcd", word2 = "pq"
Output
"apbqcd"
Explanation
Alternate until word2 ends, then append the remaining characters from word1.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.