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?
A = “abc” B = “fdh” then answer will be afbdch.
The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first line of each test contains two space-separated strings “A” and “B”.
For each test case, print a single line containing these two strings in an alternative fashion according to indices.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= |A|, |B| <= 10^5
A and B contains only lower case English characters
Time Limit: 1sec
You do not need to print anything, it has already been taken care of. Just implement the given function.
The idea here is to use recursion and append characters one by one from A and B using a variable turn. If turn equals 0 then append character from A and if turn equals 1 then append character from B to answer. If we have appended all characters from one string, then append the remaining characters of the other string to answer.
Steps :
alter(answer, A, B, indexOfA, indexOfB, turn):
The idea here is to run a loop and append characters from A and B one by one until both of them are not empty, then append the remaining characters of the non-empty string to answer.
Steps :