Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Alternate Merge of Two Arrays
00:00
5 left

Alternate Merge of Two Arrays

EasyPython

Problem

Tell me about how you would return an array by alternating elements from arrays A and B.

Implement alternate_arrays(a, b). Start with the first element of a, then take the first element of b, continuing while both arrays have elements. If one array is exhausted first, append the remaining elements from the other array in their original order.

Input: two lists of integers. Output: a new list containing all elements from both inputs.

Constraints

  • 0 <= len(a), len(b) <= 1000
  • The elements may be any integers
  • The output must contain every input element exactly once
  • The relative order within each input array must be preserved

Function Signature

def alternate_arrays(a, b):
Interviewer

Your question is Alternate Merge of Two Arrays. 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.