Reported March 2021
Bloombergdesign

Design HashMap

Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Bloomberg OA. Under 2s to a working solution.
Founder's read

Bloomberg reported this one in March 2021, and the detail that matters is the return format: put and remove give back the string "null", get gives back the value or "-1". You're building a HashMap from scratch, no built-in map allowed, and the output is an array of strings. It's a design problem that looks easy and punishes sloppy details. Keys go up to 1000000 and there are up to 100000 operations. If you've got the OA in a day or two, know the bucket-array-with-chaining approach cold. StealthCoder is the safety net if you blank during the live assessment.

The problem

Process put, get, and remove operations without using a built-in hash-table implementation for the stored map. Get returns the value or -1 when absent. Return "null" for put and remove operations.

Function
runHashMap(operations: String[], keys: int[], values: int[]) → String[]

Examples
Example 1
operations = ["put","put","get","get","put","get","remove","get"]
keys = [1,2,1,3,2,2,2,2]
values = [1,2,0,0,1,0,0,0]
return = ["null","null","1","-1","null","1","null","-1"]
The second put updates key 2, and remove makes its later get return -1.

Constraints
All arrays have equal non-zero length.
0 <= key <= 1000000
0 <= value <= 1000000
There are at most 100000 operations.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is picking a storage scheme you can write without bugs. Option one: a direct-address array of size 1000001 filled with -1. Put sets, get reads, remove resets. It's O(1) and almost impossible to get wrong, and the constraints allow it. Option two: a fixed number of buckets (say a prime near 1009), hash with key % size, and store key-value pairs in a list per bucket. That's the version interviewers expect to see discussed. The pitfalls are all small. Put on an existing key must update, not append a duplicate. Remove on a missing key still returns "null". Get on a missing key returns "-1" as a string. Values can be 0, so don't treat 0 as absent. Convert every result to a string before appending. If you freeze on the bucket logic during the live OA, StealthCoder can hand you a clean implementation while you keep your head.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Design HashMap 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 would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as design hashmap. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Bloomberg's OA.

Bloomberg reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Design HashMap FAQ

How hard is Design HashMap really?+

Easy to medium. The concept is simple, but the bugs are in the details: updating existing keys, handling remove on missing keys, and returning strings instead of ints. If you write it carefully once, it takes about ten minutes.

What's the trick for the Bloomberg version?+

Read the output format. Put and remove return the string "null" and get returns the value as a string or "-1". Then pick a simple storage plan. With keys up to 1000000, a plain array works, though buckets with chaining show real design thinking.

Can I just use an array of size 1000001?+

Yes, the constraints allow it. Fill it with -1, set on put, reset on remove. Values are 0 or greater, so -1 safely means absent. The problem only bans built-in hash tables, and a raw array isn't one. Mention chaining if asked about the general case.

How do I handle collisions if I use buckets?+

Use chaining. Each bucket holds a list of key-value pairs. On put, scan the bucket for the key and update it, or append if missing. On get, scan and return the value or -1. On remove, delete the matching pair if it exists.

How do I prepare for this in 48 hours?+

Write both versions from memory once: the direct array and the bucket chain. Then trace the sample by hand, especially the update of key 2 and the remove followed by get. Check that every output is a string. That covers most failure points.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Bloomberg.

OA at Bloomberg?
Invisible during screen share
Get it