1) Constructor: It initializes the data members as required. 2) add(value): It inserts an element into the HashSet. The function takes one argument which is the value that needs to be added and returns nothing 3) contains(value): It checks whether the element exists in the HashSet or not. The function takes one argument which is the value that needs to be searched for in the HashSet. The function returns true if the element exists, otherwise returns false. 4) remove(value): It removes an element from the HashSet. The function takes one argument which is the value that needs to be removed from the HashSet and returns the element which is being removed. If the element does not exist in the HashSet or if HashSet is empty, return -1.
Query-1 (Denoted by an integer 1)- Inserts an element in the HashSet Query-2 (Denoted by an integer 2)- Returns a boolean value denoting whether the element is present in the HashSet or not. Query-3 (Denoted by an integer 3)- Removes the element from the HashSet.
The first line of input contains an integer ‘Q’ denoting the number of queries. The next ‘Q’ lines represent the queries that need to be performed. Each query case contains two integers, two integers separated by a single space, representing the type of the operation, and a value on which operation needs to be performed.
For Query 1, you do not need to return anything. For Query 2, return true or false depending upon whether the element is present or not. For Query 3, return the element which is being removed from the HashSet.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= Q <= 10^3 1 <= query type <= 3 0 <= VALUE <= 10^6 Where ‘Q’ is the total number of queries, ‘value’ is the element that will be added, removed, or whose existence in the HashSet is to be checked. Time limit: 1 second
The idea is to store the elements in the hash table to reduce the space. To avoid a collision, chaining is used.