Challenge: Resizing a Vector
This lesson will check your knowledge of vectors.
We'll cover the following
Problem Statement #
Given a vector with an even number of elements, remove the last element from the input vector, and then the middle element. Then insert the sum of the remaining elements to the end of the resulting vector.
Input #
A vector array
Output #
An updated vector array
Sample Input #
[1, 5, 7, 9]
Sample Output #
[1, 7, 8]
Coding Exercise #
Write your code below. It is recommended​ that you try solving the exercise yourself before viewing the solution.
Note: There is a
test
function given in the code for testing purposes. Do not modify it.
Good luck! 🤞
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy