Sitemap
He Codes IT

He Codes IT

A tech blog for Computer Science Students, offering posts on courses like Databases, Data Structures, Algorithms and Data Science.

Complete reverseArray C++ Solution

1 min readAug 26, 2021

--

I came through a question on LeetCode to complete a reverseArray function. We have an array and we have to return the array reversing all the elements inside it. For Example, we have an array “X” which has elements [1,2,3,4,5,6]. We have to write a function that will return the [6,5,4,3,2,1].

Press enter or click to view image in full size

Question

Complete the reverseArray function. Parameters of reveseArray is a vector that we have to reverse. The return value must also be a vector. To read the Complete Question visit HERE

This question on LeetCode has Difficulty Level: Easy and Max Marks: 10

Get He Codes IT’s stories in your inbox

Join Medium for free to get updates from this writer.

Note: In this problem a special type of array vectors are used, which are types of dynamic arrays. They have the ability to resize themselves while inserting and deleting elements.

Given Code

#include <bits/stdc++.h>using namespace std;string ltrim(const string &);
string rtrim(const string &);
vector<string> split(const string &);
/*
* Complete the 'reverseArray' function below.
*
* The function is expected to return an INTEGER_ARRAY.
* The function accepts INTEGER_ARRAY a as parameter.
*/
vector<int> reverseArray(vector<int> a) {}

My Solution

To read about my Solution to this Problem Visit https://hecodesit.com/complete-reversearray-c-solution/

--

--

He Codes IT
He Codes IT

Written by He Codes IT

A tech blog for Computer Science Students, offering posts on courses like Databases, Data Structures, Algorithms and Data Science.