
Asked in Ernst & Young
HashMap Implementation Problem Statement
Your task is to design a data structure that efficiently stores a mapping of keys to values and performs operations in constant time.
Explanation:
1. INSERT(key, value): Add or update a mapping from a string key to an integer value. The function does not return anything.
2. DELETE(key): Remove the mapping for a key if it exists. The function does not return anything.
3. SEARCH(key): Check if the key exists in the structure. Return true if it is found, otherwise return false.
4. GET(key): Get the integer value associated with a key. If the key is not found, return -1.
5. GET_SIZE(): Return the number of key-value pairs in the data structure.
6. IS_EMPTY(): Return true if the data structure is empty, otherwise false.
Input:
The first line contains an integer 'N', denoting the number of operations to be performed. Each of the following N lines contains:
- For 'INSERT', three inputs: operation type, key (string), value (integer).
- For 'DELETE', 'SEARCH', and 'GET', two inputs: operation type, key (string).
- For 'GET_SIZE' and 'IS_EMPTY', one input: operation type.
Output:
Corresponding outputs for the operations:
- For 'INSERT': no output required.
- For 'DELETE': no output required.
- For 'SEARCH': return true if the key is present, otherwise false.
- For 'GET': return the value if the key exists, otherwise -1.
- For 'GET_SIZE': return the size of the data structure.
- For 'IS_EMPTY': return true if the data structure is empty, otherwise false.
Example:
// No specific example is provided as output depends on dynamic operations.
Constraints:
1 ≤ N ≤ 105
1 ≤ T ≤ 3
(where 'T' is the type of operation)1 ≤ V ≤ 105
(where 'V' is the value to be inserted)- Time Limit: 3 seconds
Note:
- The key is always a string.
- The value associated with a key can never be -1.

AnswerBot
4mo
Design a HashMap data structure with operations like INSERT, DELETE, SEARCH, GET, GET_SIZE, and IS_EMPTY.
Implement a hash table with efficient key-value mapping.
Ensure constant time complexity for ope...read more
Help your peers!
Add answer anonymously...
Top Technology Consultant Interview Questions Asked at Ernst & Young
Q. What are your expectations from this role?
Q. How do you detect and handle memory leaks in Node.js?
Q. What is cloud computing?
Interview Questions Asked to Technology Consultant at Other Companies
Top Skill-Based Questions for Ernst & Young Technology Consultant
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Spring Boot Interview Questions and Answers
50 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

