coding question

Upload: chanh-le

Post on 08-Feb-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/22/2019 Coding Question

    1/1

    PROBLEM

    Write a function that does the following:

    Input: An array A of length N. N is an even number and N >= 2.

    Output: A reordered array B. The first half of B contains As elements with even indices. The

    second half of B contains As elements with odd indices. Convention: the first index of an array is

    0 (and thus it is an even number).

    Input 1: [4, 8, 12, 16]

    For this array, the indices and the values are as follows:

    Index Value

    0 4

    1 8

    2 12

    3 16

    Thus, the output is as follows:

    Expected output 1: [4, 12, 8, 16]

    ADDITIONAL TEST CASE

    Input 2: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

    Expected output 2: [1, 3, 5, 7, 9, 2, 4, 6, 8, 10]

    TASK

    - Write a recursive function in a programming language of your choice (as if you are writing

    real code to be used on a production server) for the above problem

    - In addition to the main function, you are free to write helper functions (if needed)

    - The code should have as few lines as possible(but it should still be clear and readable)