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!
Select
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?
Technology Consultant Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits