easy +8 pts

Interleave Two Strings

Merge two strings alternately, starting with s1, until both are exhausted.

Write a function `interleave(s1: str, s2: str) -> str` that returns a new string formed by taking characters alternately from `s1` and `s2`, starting with `s1`. When one string is shorter, append the remaining characters of the longer string at the end. For example, `interleave("abc", "12345")` returns `"a1b2c345"` and `interleave("", "xyz")` returns `"xyz"`.

Constraints

0 <= len(s1), len(s2) <= 1000. The strings contain only printable ASCII characters.

Example

>>> interleave('abc', '123')
'a1b2c3'
>>> interleave('ab', '1234')
'a1b234'
>>> interleave('', 'xyz')
'xyz'
8 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use two index variables to track positions in each string.
In each loop iteration, take one character from s1 (if available) and then one from s2 (if available).
After the loop, any remaining characters from the longer string are appended.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.