Implementation of HashMap with Constant Time Operations
Design a data structure that effectively stores a key-value mapping and performs specific operations in constant time.
Explanation:
Your data structure should allow the following operations:
INSERT(key, value)
: Add a new (key, value) pair ifkey
does not already exist, or update the value if it does. It does not return anything.DELETE(key)
: Remove the key from storage. It returns nothing.SEARCH(key)
: Check if a key exists. Returntrue
if it does, otherwisefalse
.GET(key)
: Retrieve the value associated with the key. Return-1
if the key does not exist.GET_SIZE()
: Return the total number of key-value pairs.IS_EMPTY()
: Returntrue
if storage is empty, otherwisefalse
.
Input:
int N
Output:
varies based on operation type
Example:
Operations performed:
N = 6
1 insert key1 100
1 insert key2 200
4 get key1
5 get-size
2 delete key1
3 search key1
Expected Output:
200
2
false
Constraints:
1 <= N <= 10^5
1 <= T <= 3
1 <= V <= 10^5
Note:
- Key is a string and value is an integer.
- Value can never be -1.
Be the first one to answer
Add answer anonymously...
Popular interview questions of Software Developer Intern
>
Innovaccer Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app