Alternate Print

Easy
0/40
Average time to solve is 10m

Problem statement

You have two strings “A” and “B”. Your task is to print these two strings in an alternative fashion according to indices i.e. first character of “A”, the first character of “B”, the second character of “A”, the second character of “B” and so on.

Note:
``````If all characters of one string are printed and some characters of other string are remaining, then you have to print the remaining characters of the other string at the end of the resulting string.
``````
``````Can you solve the problem in O(N) time complexity and O(1) space complexity?
``````
For Example:
``````A = “abc” B = “fdh” then answer will be afbdch.
``````
Detailed explanation ( Input/output format, Notes, Images )
Constraints :
``````1 <= T <= 10
1 <= |A|, |B| <= 10^5
A and B contains only lower case English characters

Time Limit: 1sec
``````
Note:
``````You do not need to print anything, it has already been taken care of. Just implement the given function.
``````
Sample Input 1 :
``````2
ab the
ac ninjas
``````
Sample Output 1 :
``````atbhe
ancinjas
``````
Explanation For Sample Input 1:
``````For the first test case, A = “ab” and B = “the”
Print the first two characters of both strings in an alternative fashion,
We get “atbh” then finally append "e" to get the answer as “atbhe”

For the second test case, A = “ac” and B = “ninjas”
Printing first two characters of both strings in alternative fashion,
We will get “anci”, now append remaining characters to answer. So the answer will be  “ancinjas”.
``````
Sample Input 2 :
``````1
coding ninjas
``````
Sample Output 2 :
``````cnoidnijnags
``````
Explanation For Sample Input 2:
``````For the first test case, A = “coding” and B = “ninjas”
Printing both strings in the alternative fashion we will get “cnoidnijnags”.
``````
Console