Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerRank Vector-Sort solution in c++ programming

YASH PAL, 31 July 202422 August 2024

In this HackerRank vector-sort problem in the c++ programming language, You are given N integers.Sort the N integers and print the sorted order.

Store the N integers in a vector.Vectors are sequence containers representing arrays that can change in size.

HackerRank Vector-Sort solution in c++ programming

HackerRank Vector-Sort problem solution in c++ programming.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 
    vector<int> v;
int size;
cin>>size;
int a;
for(int i=0;i<size;i++)
{
 cin>>a;
 v.push_back(a);
}
sort(v.begin(),v.end());
 for(int i=0;i<size;i++)
    {
      cout<<v[i]<<" ";
    }
return 0;  
    return 0;
}

Second solution

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int N = 0;
    cin>>N;
    
    vector<int> vecInt;
    int number = 0;
    
    while (cin>>number)
        vecInt.push_back(number);
    
    sort(vecInt.begin(), vecInt.end());
    
    for ( vector<int>::iterator it = vecInt.begin(); it != vecInt.end(); it++)
        cout<<*it<<" ";
    return 0;
}
coding problems cpp hackerrank solutions

Post navigation

Previous post
Next post
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes