Vector-Sort C++
You are given integers N .Sort N the integers and print the sorted order. Store the N integers in a vector.Vectors are sequence containers representing arrays that can change in size. Declaration: vector<int>v; (creates an empty vector of integers) 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(); (Aft
View Solution →Vector-Erase C++
You are provided with a vector of N integers. Then, you are given 2 queries. For the first query, you are provided with 1 integer, which denotes a position in the vector. The value at this position in the vector needs to be erased. The next query consists of 2 integers denoting a range of the positions in the vector. The elements which fall under that range should be removed. The second query is performed on the updated vector which we get after performing the first query. The following are so
View Solution →Lower Bound-STL C++
You are given N integers in sorted order. Also, you are given Q queries. In each query, you will be given an integer and you have to tell whether that integer is present in the array. If so, you have to tell at which index it is present and if it is not present, you have to tell the index at which the smallest integer that is just greater than the given number is present. Lower bound is a function that can be used with a sorted vector. Input Format The first line of the input contains
View Solution →Sets-STL C++
Sets are a part of the C++ STL. Sets are containers that store unique elements following a specific order. Here are some of the frequently used member functions of sets: Declaration: set<int>s; //Creates a set of integers. Size: int length=s.size(); //Gives the size of the set. Insert: s.insert(x); //Inserts an integer x into the set s. Erasing an element: s.erase(val); //Erases an integer val from the set s. Finding an element:
View Solution →Maps-STL C++
Maps are a part of the C++ STL.Maps are associative containers that store elements formed by a combination of a key value and a mapped value, following a specific order.The mainly used member functions of maps are: Map Template: std::map <key_type, data_type> Declaration: map<string,int>m; //Creates a map m where key_type is of type string and data_type is of type int. Size: int length=m.size(); //Gives the size of the map. Insert: m.insert
View Solution →