Practice
Resources
Contests
Online IDE
New
Free Mock
Scaler
Practice
Improve your coding skills with our resources
Contests
Compete in popular contests with top coders
Scaler
Explore Offerings by SCALER

Begin your success journey!

Sign Up using
Full name *
Email *
Password *

By creating an account, I acknowledge that I have read and agree to InterviewBit’s Terms and Privacy Policy .

Welcome back!

Log In using
Email *
Password *

Vector

Vectors are same as dynamic arrays with the ability to resize itself automatically when an element is inserted or deleted, with their storage being handled automatically by the container.
Vector elements are placed in contiguous storage so that they can be accessed and traversed using iterators.

  • Declaration
    vector<int>v; (creates an empty vector of integers)
    vector<int>v(10); (creates an integer vector of size 10)
    vector<int>v(10, 0); (creates an integer vector of size 10, containing 0)
  • Size:
    int size = v.size();
  • Pushing an integer into a vector:
    v.push_back(x); (where x is an integer.The size increases by 1 after this.)
  • Popping the last element from the vector:
    v.pop_back(); (After this the size decreases by 1)
  • Sorting a vector:
    sort(v.begin(), v.end()); (Will sort all the elements in the vector)
    // begin() - Returns an iterator pointing to the first element in the vector
    // end() – Returns an iterator pointing to the theoretical element that follows the last element in the vector
  • erase(int position):
    Removes the element present at position.
    Ex: v.erase(v.begin()+4); (erases the fifth element of the vector v)
  • erase(int start,int end):
    Removes the elements in the range from start to end inclusive of the start and exclusive of the end.
    Ex: v.erase(v.begin()+2,v.begin()+5); (erases all the elements from the third element to the fifth element.)

Try the following example in the editor below.

First line of the input contains an integer denoting the number of integers.
Second line contains N space-separated integers. 
Third line contains an integer X denoting the index(0-based) of the N integers which needs to be deleted.

Your task is to print the N-1 integers in sorted order (ascending). Each integer in a new line.

Constraints

1 <= N <= 105  
0 <= X < N

Sample Input

5
10 5 2 3 10
2

Sample Output

3
5
10
10
Start solving Vector on Interview Code Editor
Hints
  • Complete Solution

Discussion


Loading...
Click here to start solving coding interview questions
Free Mock Assessment
Fill up the details for personalised experience.
All fields are mandatory
Current Employer *
Enter company name *
Graduation Year *
Select an option *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Phone Number *
OTP will be sent to this number for verification
+1 *
+1
Change Number
Graduation Year *
Graduation Year *
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
*Enter the expected year of graduation if you're student
Current Employer *
Company Name *
Please verify your phone number
Edit
Resend OTP
By clicking on Start Test, I agree to be contacted by Scaler in the future.
Already have an account? Log in
Free Mock Assessment
Instructions from Interviewbit
Start Test