Implement an Unordered Map
Updated
Problem statement
Implement an integer key-value map without using a language-provided map, dictionary, or hash-table type.
Process the operations in order:
putwith arguments[key, value]inserts the key or replaces its current value.getwith arguments[key]appends the current value to the result, or-1when the key is absent.removewith arguments[key]erases the key when it is present and otherwise does nothing.
Return the results of the get operations in their original order.
Your implementation should use hashing, resolve collisions correctly, and provide expected constant-time operations.
Function
runUnorderedMap(operations: String[], arguments: int[][]) → int[]Examples
Example 1
operations = ["put","put","get","put","get","remove","get"]arguments = [[1,10],[2,20],[1],[1,15],[1],[2],[2]]return = [10,15,-1]The first get(1) returns 10. Updating key 1 makes the next lookup return 15. After removing key 2, its lookup returns -1.
Example 2
operations = ["get","put","put","get","remove","get"]arguments = [[-5],[-5,7],[11,4],[-5],[-5],[-5]]return = [-1,7,-1]Negative keys are valid. The missing key first produces -1, then stores 7, and becomes absent again after removal.
Constraints
1 <= operations.length == arguments.length <= 200000- Each operation is
put,get, orremove. - A
putargument has length2; the other argument arrays have length1. -10^9 <= key <= 10^90 <= value <= 10^9- Do not use a built-in map, dictionary, or hash-table implementation.
More Old Mission interview questions
Similar questions at other companies
- LRU Cache for Query ResultsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- In-Memory Filesystem CommandsPerplexity AI · PHONE SCREEN · ONSITE INTERVIEWPerplexity AI interview questions
- LRU CacheServiceNow · PHONE SCREEN · ONSITE INTERVIEWServiceNow interview questions
- Mutable Points in a Hash Set and a ListMillennium · PHONE SCREENMillennium interview questions
- Rectangle Point Coverage CountsOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- File Storage ServiceCresta · PHONE SCREENCresta interview questions
- Camel CardsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Return Every Matching DecryptionDuolingo · PHONE SCREENDuolingo interview questions
- Corporation Reporting LinesMicrosoft · PHONE SCREENMicrosoft interview questions
- Key-Value Store on a Block DeviceLambda · PHONE SCREEN