Ctrl K

Interleave Two Words

Easy
You are given two strings, first and second. Build a single string by taking letters in turns: the first letter of first, the first letter of second, the second letter of first, the second letter of second, and so on. Once one string runs out, append whatever is left of the other one unchanged. Return the resulting string.
Example 1
first="cat", second="dog" → 'cdaotg'

Taking turns: c, d, a, o, t, g gives cdaotg.

Example 2
first="hi", second="there" → 'htihere'

After h, t, i, h the first word runs out, so the rest of the second, ere, is appended as is: hthiere.

Example 3
first="sun", second="" → 'sun'
Constraints
  • 0 ≤ len(first), len(second) ≤ 100
  • Both strings consist of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWhere the Fragment Starts EasyMirror Phrase Check EasySame When Flipped EasyFlip the Characters in Place EasyMirror the Vowels Easy
loading Python…
Input
first="cat", second="dog"
Expected
'cdaotg'

Run checks the first 3 tests in your browser. Submit checks all 92 tests on the server, hidden ones included.