Design a Constant Time Data Structure
Create a data structure that maintains mappings between keys and values, supporting the following operations in constant time:
1. INSERT(key, value): Add or update the integer value associated with a given string key. 2. DELETE(key): Remove the key and its associated value. 3. SEARCH(key): Check if the key exists in the data structure. Return true if it exists, otherwise false. 4. GET(key): Retrieve the value associated with the key. Return -1 if the key does not exist. 5. GET_SIZE(): Return the number of key-value pairs in the data structure. 6. IS_EMPTY(): Return true if the data structure contains no key-value pairs, otherwise return false.
Input:
The first line contains an integer 'N', representing the number of operations to be executed. The subsequent 'N' lines each correspond to one operation: For INSERT, a line contains: "1 key value" For DELETE, SEARCH, and GET, a line contains: "2 key", "3 key", or "4 key" For GET_SIZE and IS_EMPTY, a line contains only "5" or "6".
Output:
Return or display results based on operation type: Type 1: Do not return anything. Type 2: Do not return anything. Type 3: Return true or false. Type 4: Return the value, or -1 if not found. Type 5: Return the size of the data structure. Type 6: Return true if empty, otherwise false.
Example:
Input:
N = 6
1 apple 10
3 apple
4 apple
2 apple
4 apple
6
Output:
true
10
-1
true
Constraints:
- 1 <= N <= 10^5
- 1 <= T <= 3
- 1 <= V <= 10^5
- Time Limit: 3 sec
Note:
- Key is always a string value.
- Value is always a positive integer (not -1).

AnswerBot
4mo
Design a constant time data structure for key-value mappings with operations like INSERT, DELETE, SEARCH, GET, GET_SIZE, and IS_EMPTY.
Use a hash table to store key-value pairs for constant time operat...read more
Help your peers!
Add answer anonymously...
Top Software Developer Intern Interview Questions Asked at ZeMoSo Technologies
Q. What are the SQL query basics?
Q. Structure in c++
Q. Least common ancestors tree
Interview Questions Asked to Software Developer Intern at Other Companies
Top Skill-Based Questions for ZeMoSo Technologies Software Developer Intern
C++ Interview Questions and Answers
300 Questions
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Operating Systems Interview Questions and Answers
250 Questions
System Design Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

