Arrays Problem Set 3

Array.7 Reverse 3

Given an array of ints length 3, return a new array with the elements in reverse order, so {1, 2, 3} becomes {3, 2, 1}.

Test Case
Input A
Program Output
1 {1, 2, 3} {3, 2, 1}
2 {5, 11, 9} {9, 11, 5}
3 {7, 0, 0} {0, 0, 7}

Solutions:

python

raptor

Array.8 Max End 3

Given an array of ints length 3, figure out which is larger between the first and last elements in the array, and set all the other elements to be that value. Return the changed array.

Test Case
Input
Program Output
1 {1, 2, 3} {3, 3, 3}
2 {11, 5, 9} {11, 11, 11}
3 {2, 11, 3} {3, 3, 3}

Solutions:

python

raptor

Array.9 Sum 2

Given an array of ints, display the sum of the first 2 elements in the array. If the array length is less than 2, just sum up the elements that exist, returning 0 if the array is length 0.

Test Case
Input
Program Output
1 {1, 2, 3} 3
2 {1, 1} 2
3 {1, 1, 1, 1} 2

Solutions:

python

raptor