Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Alternating Characters Merge
00:00
5 left

Alternating Characters Merge

EasyPython

Problem

Simon AI displays paired event labels by interleaving characters from two strings. Given strings a and b, return a new string formed by taking one character from a, then one from b, repeating while both strings have characters remaining. Append the unused suffix of the longer string unchanged.

Formal Specification

Implement merge_alternating(a, b).

  • Input: Two strings a and b.
  • Output: A string containing all characters from a and b, in alternating order whenever both strings still have characters.
  • Alternation starts with a.
  • Empty strings are valid inputs.
  • Treat each Python string character as one character, including spaces and punctuation.

Constraints

  • 0 <= len(a), len(b) <= 10^5
  • Both inputs are valid Python strings
  • The output contains exactly len(a) + len(b) characters

Function Signature

def merge_alternating(a, b):
Interviewer

Your question is Alternating Characters Merge. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.