HashMap Operations
Basic Accuracy: 66.41% Submissions: 2485 Points: 1

Implement different operations on Hashmap. Different types of queries will be provided.
A query can be of four types:
1. a x y (adds an entry with key x and value y to the Hashmap)
2. b x (print value of  x if present in the Hashmap else print -1. )
3. c (prints the size of the Hashmap)
4. d x (removes an entry with key x from the Hashmap)

Example 1 :

Input:
5 
a 1 2 a 66 3 b 66 d 1 c 

Output:
3 1 

Explanation :
There are five queries. Queries are performed in this order
1. a 1 2  --->  map has a key 1 with value 2
2. a 66 3 ---> map has a key 66 with value 3
3. b 66   ---> prints the value of key 66 if its present in the map ie 3.
4. d 1    ---> removes an entry from map with key 1
5. c      ---> prints the size of the map ie 1

Example 2 :

Input: 
3 
a 1 66 b 5 c

Output: 
-1 1

Explanation :
There are three queries. Queries are performed in this order
1. a 1 66 ---> adds a key 1 with a value of 66 in the map
2. b 5    --->  since the key 5 is not present in the map hence -1 is printed.
3. c      ---> prints the size of the map ie 1

Your Task:
You are required to complete the following functions:
add_Value : Takes HashMap, x, y as arguments and maps x as key and y as its value. Does not return anything.
find_value : Takes HashMap and x as arguments. If HM contains x key then return the value, else return -1.
getSize : Takes HashMap as argument and just returns its size.
removeKey : Takes HashMap and x as arguments and removes x if it exists. Does not return anything.

Constraints:
1 <= Q <= 100

 

 

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

HashMap Operations

Output Window