Lesson Overview

Welcome! Today, I am thrilled to guide you through a fascinating task involving vectors in C++: pairing up 'opposite' elements. Specifically, we're going to learn how to access and manipulate elements within a C++ vector. The task at hand provides an excellent opportunity to elevate your vector-handling skills within the C++ language. Are you ready to get started? Let's dive right in!

Task Statement and Description

Our task today is to form pairs of 'opposite' elements in a given vector of integers. In a vector consisting of n elements, the first and last elements are known as 'opposite', the second element and the second last element are considered 'opposite', and so on. For a vector with an odd length, the middle element is its own 'opposite'.

You will be provided with a vector of n integers. The value of n could range from 1 to 100, inclusive. The task will require you to return a std::vector of std::pair objects. Each std::pair consists of an element and its 'opposite' element.

Let's use example vector numbers as {1, 2, 3, 4, 5} to simplify our understanding. In this case, the output of our solution(numbers) function will be .

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal