id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

orion.a.smith@gmail.com apcsa-arrays > apcsaArraysAlternateInputs
prev  |  next  |  chance

Heads up, this is a harder problem. Congratulations on making it here!


Given two arrays of ints, return a new array of ints which has all the elements from the two original arrays, alternating.  That means that the output starts with the first element of a, followed by the first element of b, followed by the second element of a, then the second element of b and so forth.  If you run out of elements from one array, continue on with all the remaining elements from the other array.  Precondition: both inputs will have at least one element.

HINT: the output array will be sized to the length of the sum of the lengths of the input arrays.

apcsaArraysAlternateInputs([1, 2, 3], [-1, -2, -3]) → [1, -1, 2, -2, 3, -3]
apcsaArraysAlternateInputs([1, 12], [18, 26, 44, 50]) → [1, 18, 12, 26, 44, 50]
apcsaArraysAlternateInputs([0], [1]) → [0, 1]

...Save, Compile, Run (ctrl-enter)

public int[] apcsaArraysAlternateInputs(int[] a, int[] b) { }

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Java Help

Misc Code Practice

Difficulty: 260

Copyright Nick Parlante 2017 - privacy