Important functions of STL Components in C++

STL provides a range of data structures that are very useful in various scenarios. A lot of data structures are based on real-life applications. It is a library of container classes, algorithms, and iterators. It is a generalized library and so, its components are parameterized.

Most common Data Structures used are:

  1. Vector
  2. Stack
  3. Queue
  4. Priority queue
  5. Set
  6. List
  7. Ordered Maps
  8. Unordered Maps

Containers or container classes store objects and data. There are in total seven standards “first-class” container classes and three container adaptor classes and only seven header files that provide access to these containers or container adaptors.

Note: We can include just one library, i.e., #include <bits/stdc++.h> that includes all the STL libraries but in certain competitions, including this library can make the code slow. To overcome this problem, we can add specific libraries to access particular data structures of STL. Also while removing the elements, it is required to take care if the data structure is empty or not. Calling remove function on an empty data structure leads to error. Below are the some Data Structures with their illustration shown

  1. Vector: The major problem while using arrays was that we had to specify size. This drawback was overcome by vectors. Vectors internally work as dynamically allocated arrays, which is the main reason as to how we can add elements without specifying the size of the vector. When the size of the vector becomes equal to capacity, the capacity of vector increases and thus we can add further elements.

    Header file:



    #include <vector>

    Syntax:

    vector<data type> variable_name;

    Most common function for vector:

    1. push_back(): Used to push the element at the end of the vector. For faster method, use emplace_back().
    2. pop_back(): Used to remove the last element from the vector.
    3. size(): Returns the size of the vector.
    4. clear(): Deletes all the content of the vector.
    5. erase(): Deletes the specified index or data.
    6. empty(): Returns boolean value True if vector is empty, else returns False.
    7. Iterator lower_bound(Iterator first, Iterator last, const val): lower_bound returns an iterator pointing to the first element in the range [first, last) which has a value not less than ‘val’.
    8. Iterator upper_bound(Iterator first, Iterator last, const val): upper_bound returns an iterator pointing to the first element in the range [first, last) which has a value greater than ‘val’.

    Below is the code to implement the above functions:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // C++ program to illustrate the
    // function of vector in C++
    #include <iostream>
      
    // Header file for vector if
    // <bits/stdc++.h> not included
    #include <vector>
    using namespace std;
      
    // Function to print the vector
    void print(vector<int> vec)
    {
      
        // vec.size() gives the size
        // of the vector
        for (int i = 0; i < vec.size(); i++) {
            cout << vec[i] << " ";
        }
      
        cout << endl;
    }
      
    // Driver Code
    int main()
    {
        // Defining a vector
        vector<int> vec;
      
        // Put all natural numbers
        // from 1 to 10 in vector
        for (int i = 1; i <= 10; i++) {
            vec.push_back(i);
        }
      
        cout << "Initial vector: ";
      
        // print the vector
        print(vec);
      
        // Size of vector
        cout << "Vector size: "
             << vec.size() << "\n";
      
        // Check of vector is empty
        if (vec.empty() == false)
            cout << "Is vector is"
                 << " empty: False\n";
      
        // Popping out 10 form the vector
        vec.pop_back();
        cout << "Vector after popping: ";
        print(vec);
      
        // Deleting the first element
        // from the vector using erase()
        vec.erase(vec.begin());
        cout << "Vector after erase"
             << " first element: ";
        print(vec);
      
        // Clear the vector
        vec.clear();
        cout << "Vector after "
             << "clearing: None ";
        print(vec);
      
        // Check if vector is empty
        if (vec.empty() == true)
            cout << "Is vector is"
                 << " empty: True\n";
    }

    chevron_right

    
    

    Output:

    Initial vector: 1 2 3 4 5 6 7 8 9 10
    Vector size: 10
    Is vector is empty: False
    Vector after popping: 1 2 3 4 5 6 7 8 9
    Vector after erase first element: 2 3 4 5 6 7 8 9
    Vector after clearing: None
    Is vector is empty: True

  2. Stack: It is Last In First Out (LIFO) data structure. It can be implemented using arrays, linked lists, and vectors. Some problems like reversing an element or string, parenthesis check, print next greater element, postfix expression, etc, can be done using stack class rather than making all the functions we can use its inbuilt functions.



    Header file:

    #include <stack>

    Syntax:

    stack<data_type> variable_name;

    Most common function for stack:

    1. push(): Used to push the element at top of the stack.
    2. pop(): Deletes the top element of the stack but do not returns it.
    3. top(): Returns the top element of the stack.
    4. empty(): Return boolean value, ie, True if stack is empty, else returns false.
    5. size(): Returns the size of the stack.

    Below is the code to implement the above functions:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // C++ program to illustrate the
    // function of stack in C++
    #include <iostream>
      
    // Header file for stack
    #include <stack>
    using namespace std;
      
    // Function to print the stack
    void print(stack<char> s)
    {
      
        // Loops runs till stack
        // becomes empty
        while (s.empty() == false) {
      
            // Prints the top element
            cout << s.top() << " ";
      
            // Now pops the same top element
            s.pop();
        }
      
        cout << "\n";
    }
      
    // Driver Code
    int main()
    {
        // Given char array
        char array[]
            = { 'G', 'E', 'E', 'K',
                'S', 'F', 'O', 'R', 'G',
                'E', 'E', 'K', 'S' };
      
        // Defining stack
        stack<char> s;
      
        // Check if stack is empty
        if (s.empty() == true) {
            cout << "Stack is currently Empty"
                 << "\n";
        }
        else {
            cout << "Stack is not empty"
                 << "\n";
        }
      
        // Push elements in stack
        for (int i = sizeof(array) / sizeof(array[0]) - 1;
             i >= 0; i--) {
            s.push(array[i]);
        }
      
        // Size of stack
        cout << "Size of stack: "
             << s.size() << "\n";
      
        // Content of stack
        cout << "Stack initially: ";
        print(s);
      
        // Returning the top
        // element of the stack
        cout << "Top element: "
             << s.top() << "\n";
      
        // Popping the top
        // element in stack
        s.pop();
      
        cout << "Stack after 1"
             << "pop operation: ";
        print(s);
      
        // Now checking the top element
        cout << "Top element after popping: "
             << s.top() << "\n";
      
        // Size of stack
        cout << "Size of stack"
             << "after popping: "
             << s.size() << "\n";
      
        // Again checking if the
        // stack is empty
        if (s.empty() == true) {
            cout << "Stack is currently Empty"
                 << "\n";
        }
        else {
            cout << "Stack is not empty"
                 << "\n";
        }
        return 0;
    }

    chevron_right

    
    

    Output:

    Stack is currently Empty
    Size of stack: 13
    Stack initially: G E E K S F O R G E E K S
    Top element: G
    Stack after 1pop operation: E E K S F O R G E E K S
    Top element after popping: E
    Size of stackafter popping: 12
    Stack is not empty

  3. Queue: It is First In First Out (FIFO) data structure.The reason why we require queues use a lot of practical application of first in first out and when data doesn’t need to be processed early. For example, in a queue for buying tickets for a show, the one who enters the queue first, get the ticket first. It can be implemented using arrays, linked lists, and vectors just like stacks. Some applications of queue include level-order traversal in trees and graphs, in resource sharing, etc.
    Header file:

    #include <queue>



    Sytax:

    queue<Data Type> variable_name;

    Most common function fo Queue:

    1. push(): Used to push the element at back of the queue
    2. pop(): Deletes the front element of the queue but does not return it.
    3. front(): Returns the front element of the queue, or the element that is first in the line.
    4. empty(): Return boolean value, ie, True if queue is empty, else returns false
    5. back(): Returns the last element of queue.
    6. size(): Returns the size of the queue.

    Below is the code to implement the above functions:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // C++ program to illustrate the
    // function of vector in C++
    #include <iostream>
      
    // Header file for queue
    #include <queue>
    using namespace std;
      
    // Function to print the queue
    void print(queue<char> q)
    {
        for (int i = 0; i < q.size(); i++) {
      
            // Printing the front element
            cout << q.front() << " ";
      
            // Popping the front element
            q.pop();
        }
      
        cout << "\n";
    }
      
    // Driver Code
    int main()
    {
        // Given array
        char array[]
            = { 'G', 'E', 'E', 'K', 'S' };
      
        // Defining queue
        queue<char> q;
      
        if (q.empty() == true) {
            cout << "Queue is empty\n";
        }
      
        for (int i = 0; i < 5; i++) {
            q.push(array[i]);
        }
      
        cout << "Queue Initally: ";
        print(q);
      
        // Front element
        cout << "Front element: "
             << q.front() << "\n";
      
        // Back element
        cout << "Back Element: "
             << q.back() << "\n";
      
        // Size of queue
        cout << "Size of queue: "
             << q.size() << "\n";
      
        // Empty
        if (q.empty() == false) {
            cout << "Queue is not empty\n";
        }
        return 0;
    }

    chevron_right

    
    

    Output:

    Queue is empty
    Queue Initally: G E E
    Front element: G
    Back Element: S
    Size of queue: 5
    Queue is not empty

  4. Priority Queue: This data structure is similar to queues, but the order of first out is decided by a priority set by the user. The main functions include getting top priority element, insert, delete the top priority element or decrease the priority. Data structure Heaps is used and not BST, as in BST, creating trees is costly than heaps, and the complexity of heaps is better. Also, heaps provide Complete Binary Tree and Heap order property satisfying all the properties of Priority Queue. Priority Queue has 2 variations, Min Heap and Max Heap. 
    Complex problems like finding k largest or smallest elements, merge k unsorted arrays, Dijkstra’s Shortest Path Algorithm, Huffman code for compression, Prim’s Algorithm, etc. can be implemented easily.

    Header file:

    #include <queue>

    Syntax:



    Min Priority Queue: priority_queue<Data Type> variable_name;
    Max Priority Queue: priority_queue <Data Type, vector, greater> variable_name;

    Most common function fo priority queue:

    1. push(): Used to push the element in the queue
    2. pop(): Deletes the top priority element of the queue but does not return it. Deletes element with max priority in max heap else deletes min element
    3. size(): Returns the size of the queue.
    4. empty(): Returns boolean value, ie, true if queue is empty, else return false.
    5. top(): Returns the top element of the queue. In max priority queue, it returns the maximum, while in min priority queue, it returns the minimum value.

    Below the use of above function:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // C++ program to illustrate the
    // function of priority queue in C++
    #include <iostream>
      
    // Header file for priority
    // queue, both MIN and MAX
    #include <queue>
    using namespace std;
      
    // Function to print the
    // min priority queue
    void print_min(priority_queue<int,
                                  vector<int>,
                                  greater<int> >
                       q)
    {
        while (q.empty() == false) {
      
            // Print the front
            // element(MINIMUM)
            cout << q.top() << " ";
      
            // Pop the minimum
            q.pop();
        }
        cout << "\n";
    }
      
    // Function to print the
    // min priority queue
    void print_max(priority_queue<int> q)
    {
        while (q.empty() == false) {
      
            // Print the front
            // element(MAXIMUM)
            cout << q.top() << " ";
      
            // Pop the maximum
            q.pop();
        }
        cout << "\n";
    }
      
    // Driver Code
    int main()
    {
        // MIN priority queue
        priority_queue<int> max_pq;
      
        // MAX priority_queue
        priority_queue<int, vector<int>,
                       greater<int> >
            min_pq;
      
        // Is queue empty
        if (min_pq.empty() == true)
            cout << "MIN priority "
                 << "queue is empty\n";
      
        if (max_pq.empty() == true)
            cout << "MAX priority"
                 << " queue is empty\n";
      
        cout << "\n";
      
        for (int i = 1; i <= 10; i++) {
            min_pq.push(i);
            max_pq.push(i);
        }
      
        cout << "MIN priority queue: ";
        print_min(min_pq);
      
        cout << "MAX priority queue: ";
        print_max(max_pq);
        cout << "\n";
      
        // Size
        cout << "Size of min pq: "
             << min_pq.size() << "\n";
        cout << "Size of max pq: "
             << max_pq.size() << "\n";
        cout << "\n";
      
        // Top element
        cout << "Top of min pq: "
             << min_pq.top() << "\n";
        cout << "Top of max pq: "
             << max_pq.top() << "\n";
        cout << "\n";
      
        // Pop the front element
        min_pq.pop();
        max_pq.pop();
      
        // Queus after popping
        cout << "MIN priority "
             << "queue after pop: ";
        print_min(min_pq);
        cout << "MAX priority "
             << "queue after pop: ";
        print_max(max_pq);
        cout << "\n";
      
        // Size after popping
        cout << "Size of min pq: "
             << min_pq.size() << "\n";
        cout << "Size of max pq: "
             << max_pq.size() << "\n";
        cout << "\n";
      
        // Is queue empty
        if (min_pq.empty() == false)
            cout << "MIN priority "
                 << " queue is not empty\n";
      
        if (max_pq.empty() == false)
            cout << "MAX priority queue"
                 << " is not empty\n";
    }

    chevron_right

    
    

    Output:

    MIN priority queue is empty
    MAX priority queue is empty

    MIN priority queue: 1 2 3 4 5 6 7 8 9 10
    MAX priority queue: 10 9 8 7 6 5 4 3 2 1

    Size of min pq: 10
    Size of max pq: 10

    Top of min pq: 1
    Top of max pq: 10

    MIN priority queue after pop: 2 3 4 5 6 7 8 9 10
    MAX priority queue after pop: 9 8 7 6 5 4 3 2 1

    Size of min pq: 9
    Size of max pq: 9



    MIN priority queue is not empty
    MAX priority queue is not empty

  5. Set: Sets are associative containers in which each element is unique. The elements cannot be modified once inserted in the set. A set ignores the duplicate values and all the elements are stored in sorted order. This data structure is particularly useful when incoming elements need to be sorted and modification is not required.
    The sets can store elements in two orders, increasing order or decreasing order.
    Header file:

    #include <set> 

    Syntax:

    Increasing order: set<Data type> variable_name;

    Decreasing order :set<Data type, greater<Data type> > variable_name; 

    Most common function fo Set:

    1. insert(): This function is used to insert a new element in the Set.
    2. begin(): This function returns an iterator to the first element in the set.
    3. end(): It returns an iterator to the theoretical element that follows the last element in the set.
    4. size(): Returns the total size of the set.
    5. find(): It returns an iterator to the searched element if present. If not, it gives an iterator to the end.
    6. count(): Returns the count of occurrences in a set. 1 if present, else 0.
    7. empty(): Returns boolean value, ie, true if empty else false.

    Below is the code to implement the above functions:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // C++ program to illustrate functions
    // of set in C++
    #include <iostream>
      
    // Header file for set
    #include <set>
    using namespace std;
      
    // Function to print the set
    void print_min(set<int> s)
    {
        cout << "Min set: ";
        set<int>::iterator itr;
        for (itr = s.begin();
             itr != s.end(); ++itr) {
            cout << *itr << " ";
        }
        cout << endl;
    }
      
    // Function to print the set
    void print_max(set<int,
                       greater<int> >
                       s)
    {
        cout << "Max set: ";
        set<int, greater<int> >::iterator itr;
        for (itr = s.begin();
             itr != s.end(); ++itr) {
            cout << *itr << " ";
        }
        cout << endl;
    }
      
    // Driver Code
    int main()
    {
        // Defining set stores values in
        // increasing order
        set<int> min_set;
      
        // stores values in decreasing order
        set<int, greater<int> > max_set;
      
        // Empty
        if (min_set.empty() == true) {
            cout << "Min set is empty\n";
        }
        if (max_set.empty() == true) {
            cout << "Max set is empty\n";
        }
        cout << endl;
      
        // Inserting into the set
        for (int i = 1; i <= 10; i++) {
            min_set.insert(i);
            max_set.insert(i);
        }
      
        // Printing the set
        print_min(min_set);
        print_max(max_set);
        cout << endl;
      
        // Size
        cout << "Size of min set: "
             << min_set.size() << "\n";
        cout << "Size of max set: "
             << max_set.size() << "\n";
        cout << endl;
      
        // Empty
        if (min_set.empty() == false) {
            cout << "Min set is not empty\n";
        }
        if (max_set.empty() == false) {
            cout << "Max set is not empty\n";
        }
        cout << endl;
    }

    chevron_right

    
    

    Output:

    Min set is empty
    Max set is empty



    Min set: 1 2 3 4 5 6 7 8 9 10
    Max set: 10 9 8 7 6 5 4 3 2 1

    Size of min set: 10
    Size of max set: 10

    Min set is not empty
    Max set is not empty

  6. List: Lists stores data in non-contiguous manner.Elements of the list can be scattered in the different chunks of memory.Access to any particular index becomes costly as traversal from know index to that particular index has to be done, hence it is slow than vector.Zero-sized lists are also valid.
    Header file:

    #include <list> 

    Syntax:

    list<Data Type> variable_name;

    Most common function fo list:

    1. push_front(element): Inserts a new element ‘element’ at the beginning of the list .
    2. push_back(element) : Inserts a new element ‘element’ at the end of the list.
    3. pop_front(): Removes the first element of the list.
    4. pop_back(): Removes the last element of the list.
    5. front() : Returns the value of the first element in the list.
    6. back() : Returns the value of the last element in the list .
    7. empty(): Returns boolean value, ie, true if empty else false.

    Below is the code to implement the above functions:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // C++ program to illustrate the above
    // functions in list
    #include <iostream>
      
    // Header file for lists
    #include <list>
    using namespace std;
      
    // Function to print the list
    void print(list<int> l)
    {
        list<int>::iterator it;
      
        for (it = l.begin();
             it != l.end(); ++it)
            cout << *it << " ";
      
        cout << '\n';
    }
      
    // Driver Code
    int main()
    {
        // Defining integer list
        list<int> l;
      
        // Pushing the elements
        for (int i = 0; i < 10; ++i) {
            l.push_back(i * 2);
        }
      
        // Printing the list
        cout << "List initally is : ";
        print(l);
      
        // Front element
        cout << "Front element: "
             << l.front() << "\n";
      
        cout << "List after Popping"
             << " the front element: ";
        l.pop_front();
        print(l);
      
        // Last element
        cout << "Last element: "
             << l.back() << "\n";
      
        cout << "List after Popping"
             << " the last element: ";
        l.pop_back();
        print(l);
      
        // Reversing the list
        cout << "Reverse the list: ";
        l.reverse();
        print(l);
      
        // Soring the list
        cout << "Sort the list: ";
        l.sort();
        print(l);
    }

    chevron_right

    
    

    Output:



    List initally is : 0 2 4 6 8 10 12 14 16 18
    Front element: 0
    List after Popping the front element: 2 4 6 8 10 12 14 16 18
    Last element: 18
    List after Popping the last element: 2 4 6 8 10 12 14 16
    Reverse the list: 16 14 12 10 8 6 4 2
    Sort the list: 2 4 6 8 10 12 14 16

  7. Unordered Maps: Suppose you have a pencil box and some pens. You put some pens in the box, that would be random and not ordered unlike ordered maps but you can access any pen and work with it. The same is unordered maps, the elements are stored randomly but you can access any order anytime. The main difference is between ordered maps and unordered maps are the way the compiler stores them. It has two arguments, the first is called KEY, and the other is called Value. The keymaps to the value and is always unique.

    Header file:

    #include <unordered_map>

    Syntax:

    unordered_map<Data Type> variable name;

    Most common function fo unordered map:

    1. count(): Returns boolean values, ie, 1 if the key passes exists, else false.
    2. erase(key) : Returns the passed key.
    3. clear() : Deletes the entire map.
    4. size() : Returns the size of the map.

    Note: Unordered maps do not suppose pairs, ie, neither the key nor the value can have pair or similar data type/structure. In such cases, we need to explicitly create and define the required data structure to satisfy needs.

    Below is the code for the above functions:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // C++ program to implement the above
    // functionalities in unordered_map
    #include <iostream>
      
    // Header file for unordered maps
    #include <unordered_map>
    using namespace std;
      
    // Prints the map
    void print(unordered_map<int, int> m)
    {
        for (auto i = m.begin();
             i != m.end(); i++) {
            std::cout << i->first
                      << " : " << i->second << '\n';
        }
        cout << endl;
    }
      
    // Driver Code
    int main()
    {
        // Defining unordered map
        unordered_map<int, int> m;
      
        // Enters the soecified value
        for (int i = 0; i < 10; i++) {
            m[i] = 1;
        }
      
        // Print the map
        cout << "Map initially: \n";
        print(m);
      
        // Incresing value of
        // certain keys by 1
        for (int i = 0; i < 10; i += 4) {
            m[i] += 10;
        }
      
        // Print the map
        cout << "Map after increasing"
             << " value: \n";
        print(m);
      
        // Size
        cout << "Size: " << m.size()
             << "\n";
      
        // count method to see if
        // 20 is present or not
        if (m.count(20) == 0) {
            cout << "20 is not present"
                 << " in map\n";
        }
      
        // count method to see if 4
        // is present or not
        if (m.count(4) == 1) {
            cout << "4 is not present in"
                 << " map with the value " << m[4] << "\n";
        }
    }

    chevron_right

    
    

    Output:



    Map initially:
    9 : 1
    8 : 1
    7 : 1
    6 : 1
    1 : 1
    0 : 1
    2 : 1
    3 : 1
    4 : 1
    5 : 1

    Map after increasing value:
    9 : 1
    8 : 11
    7 : 1
    6 : 1
    1 : 1
    0 : 11
    2 : 1
    3 : 1
    4 : 11
    5 : 1

    Size: 10
    20 is not present in map
    4 is not present in map with the value 11

  8. Ordered Maps: Suppose you have a new shelf in your room and some books. You arrange the books one after another but after arranging any number of books, you can access arranged books in any order and keep the book in the same place when you’ve read it. This is an example of a map. You fill the values one after another in order and the order is maintained always, but you can access any element anytime. This data structure is also implemented using dynamic arrays. Like unordered maps, it has two arguments, the first is called KEY, and the other is called Value. The keymaps to the value and is always unique.

    Header file:

    #include <ordered_map>

    Syntax:

    ordered_map<Data Type> variable name;

    Most common function fo orderd map:

    1. count() : Returns boolean values, ie, 1 if the key passes exists, else false.
    2. erase(key): Returns the passed key.
    3. clear(): Deletes the entire map.
    4. size(): Returns the size of the map.

    Note: Ordered maps do not suppose pairs, ie, neither the key nor the value can have pair or similar data type/structure. In such cases, we need to explicitly create and define the required data structure to satisfy needs.



    Comparison between ordered and unordered maps can be found here. The difference is basically the time complexity as ordered maps have better time complexity in worse cases than unordered maps.

    Below is the code for the above functions:

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // C++ program to implement the above
    // functionalities in unordered_map
    #include <iostream>
      
    // Header file for ordered maps
    #include <map>
    using namespace std;
      
    // Prints the map
    void print(map<int, int> m)
    {
        for (auto i = m.begin();
             i != m.end(); i++) {
            std::cout << i->first
                      << " : " << i->second << '\n';
        }
        cout << endl;
    }
      
    // Driver Code
    int main()
    {
        // Defining ordered map
        map<int, int> m;
      
        // Enters the soecified value
        for (int i = 0; i < 10; i++) {
            m[i] = 1;
        }
      
        // Print the map
        cout << "Map initially: \n";
        print(m);
      
        // Incresing value of
        // certain keys by 1
        for (int i = 0; i < 10; i += 4) {
            m[i] += 10;
        }
      
        // Print the map
        cout << "Map after increasing value: \n";
        print(m);
      
        // Size
        cout << "Size: " << m.size() << "\n";
      
        // count method to see if 20
        // is present or not
        if (m.count(20) == 0) {
            cout << "20 is not present in map\n";
        }
      
        // count method to see if 4
        // is present or not
        if (m.count(4) == 1) {
            cout << "4 is not present in"
                 << " map with the value " << m[4] << "\n";
        }
    }

    chevron_right

    
    

    Output:

    Map initially:
    0 : 1
    1 : 1
    2 : 1
    3 : 1
    4 : 1
    5 : 1
    6 : 1
    7 : 1
    8 : 1
    9 : 1

    Map after increasing value:
    0 : 11
    1 : 1
    2 : 1
    3 : 1
    4 : 11
    5 : 1
    6 : 1
    7 : 1
    8 : 11
    9 : 1

    Size: 10
    20 is not present in map
    4 is not present in map with the value 11

competitive-programming-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.