Design Hash Map
Reported by candidates from Apple's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Apple's August 2026 OA reportedly asks you to build a hash map from scratch, and the whole question hinges on one data structure: an array of buckets. No built-in map, dict, or hash table allowed for the stored entries. If you've only ever used one, writing your own feels strange under a timer. The good news is the spec is small: put, get, remove, and a result array for the gets. Candidates who've seen it call it a warm-up that punishes sloppy edge cases. StealthCoder sits invisibly on your screen as a safety net if your mind goes blank mid-assessment, but the shape of this solution is simple enough to carry in your head.
The problem
Implement a hash map that stores integer values under integer keys. Build the storage yourself without using a language's built-in hash table, map, or dictionary for the stored entries. Process the arrays from left to right. At index i: "put" stores values[i] under keys[i]. If the key already exists, replace its value. "get" appends the value stored under keys[i] to the result, or appends -1 when the key is absent. "remove" deletes keys[i] when present. Removing a missing key has no effect. Return an integer array containing the results of all get operations in encounter order. Function runHashMap(operations: String[], keys: int[], values: int[]) → int[] Examples Example 1 operations = ["put","put","get","get","put","get","remove","get"] keys = [1,2,1,3,2,2,2,2] values = [10,20,0,0,25,0,0,0] return = [10,-1,25,-1] The first two queries return 10 and -1. Updating key 2 changes its value to 25, and removing it makes the final query return -1. Example 2 operations = ["remove","put","get","put","get","remove","get"] keys = [0,0,0,0,0,0,0] values = [0,0,0,7,0,0,0] return = [0,7,-1] Removing missing key 0 has no effect. The first insertion stores 0, the second insertion replaces it with 7, and the last query occurs after removal. Constraints 1 <= operations.length <= 100000. operations.length == keys.length == values.length. Every operation is "put", "get", or "remove". 0 <= keys[i] <= 1000000. For every put operation, 0 <= values[i] <= 1000000.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is bucketing. Pick a bucket count, say a prime near 10007 or so, and hash each key with key % size. Each bucket holds a small list of key/value pairs. Put scans the bucket, updates if the key exists, otherwise appends. Get scans and returns the value or -1. Remove scans and deletes the pair if found. With up to 100000 operations and keys up to 1000000, chaining stays fast. The common pitfalls: forgetting that put on an existing key must replace, not duplicate, and returning 0 instead of -1 for a missing key, since 0 is a valid stored value. Example 2 tests exactly that. Another trap is removing from a list while iterating it. Break right after the delete. Since keys are bounded by 1000000, a direct-address array also works, but the bucket approach is what an interviewer expects. If you freeze on the chaining details during the live OA, StealthCoder is the hedge that gets you unstuck.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Design Hash Map cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as design hashmap. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Apple's OA.
Apple reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Design Hash Map FAQ
How hard is the Apple Design Hash Map question really?+
It's easy on algorithm difficulty, but it's about clean implementation. There's no clever insight, just buckets, a hash function, and careful handling of update, missing keys, and removal. Most failures come from edge cases like returning -1 correctly, not from the core idea.
What's the trick to solving it?+
Use an array of buckets and hash with key % bucketSize. Store key/value pairs in each bucket. Every operation scans just one small bucket. That gives near constant time per operation, which is plenty for 100000 operations.
Can I just use a big array since keys max out at 1000000?+
Probably yes, since keys go up to 1000000 and the constraints allow it. Initialize an array of size 1000001 with -1 and index directly. But it sidesteps the spirit of the problem, and a bucket-based version is safer if the checker or reviewer expects a real hash design.
What edge cases break most solutions?+
Removing a key that doesn't exist, putting the same key twice, and a stored value of 0 being confused with absent. Example 2 covers all three. Also make sure you only append to the result on get operations, in order.
How do I prepare in 48 hours?+
Write a bucket-chaining hash map from memory twice, then trace both examples by hand. Practice the update-in-place and delete-from-bucket logic until it's automatic. Also skim related design problems like LRU-style structures, but this one needs only the basics.