Sort and Reverse Vector | Practice | GeeksforGeeks

You are given a vector V of size n. You need to sort it and reverse it.
Example 1: 
Input:
n = 5
V = 1 2 3 4 5
Output: 
1 2 3 4 5
5 4 3 2 1

Your Task:
Since this is a function problem, you don't need to take any input. Just complete the provided functions sortVector() and reverseVector(). Return the vector after performing suitable operations.
Constraints:
1 <= n <= 107
0 <= Vi <= 107
0
mayank180919991 week ago
vector<int> sortVector(vector<int>v)
{
   //Your code here. Use library function
   sort(v.begin(),v.end());
    return v;
}
vector<int> reverseVector(vector<int>v)
{
     //Your code here. Use library function
     sort(v.rbegin(),v.rend());
    return v;
}
0
akash119027401 month ago
vector<int> sortVector(vector<int>v){  //Your code here. Use library function   sort(v.begin(),v.end());   return v;}vector<int> reverseVector(vector<int>v){    //Your code here. Use library function   reverse(v.begin(),v.end());   return v;}
0
bickyjha0553 months ago
vector<int> sortVector(vector<int>v){  sort(v.begin(),v.end());   return v;}vector<int> reverseVector(vector<int>v){     //both are correct use one      sort(v.begin(),v.end(), greater<int> ());     // reverse(v.begin(), v.end()) ;   return v;}
+1
gaurlakshya24265 months ago
C++ Solution →
vector<int> sortVector(vector<int>v)
{
   //Your code here. Use library function
   sort(v.begin(),v.end());
   
    return v;
}
vector<int> reverseVector(vector<int>v)
{
     //Your code here. Use library function
   reverse(v.begin(),v.end());
    return v;
}
0
vs6968716 months ago
why this code not submit ??
whats wrong??
 
 
vector<int> reverseVector(vector<int>v){   sort(v.begin() , v.end());   reverse(v.begin(), v.end());   return v;}
0
Dhruv Mishra_18267 months ago
Dhruv Mishra_1826
vector<int> sortVector(vector<int>v){   //Your code here. Use library function   sort(v.begin(),v.end());    return v;}vector<int> reverseVector(vector<int>v){     //Your code here. Use library function     reverse(v.begin(),v.end());    return v;}
0
Shapnesh Singh Tiwari8 months ago
Shapnesh Singh Tiwari
https://youtu.be/7_FRLQoP26c
0
Purushottam Bca9 months ago
Purushottam Bca
CORRECT ANSWER  
 vector<int> sortVector(vector<int>v){    sort(v.begin(),v.end());    return v;}vector<int> reverseVector(vector<int>v){     sort(v.begin(),v.end(), greater<int>());    return v;}
0
ArBoss
This comment was deleted.
0
Manikanth Kr1 year ago
Manikanth Kr
c++ code:vector<int> sortVector(vector<int>v){   //Your code here. Use library function   sort(v.begin(),v.end());    return v;}vector<int> reverseVector(vector<int>v){     //Your code here. Use library function     reverse(v.begin(),v.end());    return v;}
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.