Two apprentice weavers, A and B, are collaborating on a single ceremonial tapestry. Weaver A holds a sequence of thread-color codes and Weaver B holds another. Starting with Weaver A, the two take turns adding exactly one thread-color code to the tapestry — first A's next code, then B's next code, and so on — until one of them runs out of codes. The weaver who still has codes left then adds all of their remaining codes, in order, to finish the tapestry. Given both weavers' thread-color sequences, determine the final tapestry sequence.
The first line contains a string a, Weaver A's thread-color sequence. The second line contains a string b, Weaver B's thread-color sequence. Both strings consist only of lowercase English letters.
Print a single string: the final tapestry sequence produced by alternating characters from a and b, starting with a, and appending any leftover characters from the longer string at the end.
Example 1
Input
abc pqr
Expected
apbqcr
Explanation
Weaver A contributes 'a', then Weaver B contributes 'p', then A contributes 'b', B contributes 'q', then A contributes 'c', B contributes 'r'. Both sequences are exhausted at the same time, giving the tapestry 'apbqcr'.
Example 2
Input
ab pqrs
Expected
apbqrs
Explanation
The weavers alternate 'a', 'p', 'b', 'q', at which point Weaver A's sequence of length 2 is exhausted. Weaver B still has 'r' and 's' left, which are appended in order, giving the final tapestry 'apbqrs'.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →