Challenge: Resizing a Vector

This lesson will check your knowledge of vectors.

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.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy