FunctionRacerProblemsRace

Merge Strings Alternately

EasyStringsPython, JavaScript, TypeScript, Java, C++

Build a string by taking one letter from word1, then one from word2, then the next from word1, and so on. When one string runs out, add all remaining letters of the other string to the end.

Example 1

word1 "abc"
word2 "pqr"
returns "apbqcr"

Alternating gives apbqcr.

Example 2

word1 "ab"
word2 "pqrs"
returns "apbqrs"

apbq then the rest rs.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems