Intuition
We are required to merge two strings such that the resulting string has alternating characters both input strings.
Sounds straightforward, but what about the edge-case that one of the string is shorter than the other? In that case we do the alternating - till that index in both strings and then just concatenate the remainder of the substring from the longer string. Now does it sound straightforward? Worry not, it is from here.
Code
Python3
Big O Analysis
-
Runtime
The runtime complexity here is since we are iterating for the shorter string duration.
-
Memory
The memory usage is since we are not using any extra data structure.
— A