[
string
two pointers
]
BinarySearch 0096 Interleaved String
Problem statement
https://binarysearch.com/problems/Interleaved-String/
Solution
All we need to to use two pointers here and merge strings.
Complexity
It is O(n + m)
for time and space.
Code
class Solution:
def solve(self, s0, s1):
ans, i = [], 0
while i < len(s0) and i < len(s1):
ans += [s0[i], s1[i]]
i += 1
ans += s0[i:]
ans += s1[i:]
return "".join(ans)