Reported May 2018
Bloombergdesign

Implement a Dynamic Array Vector

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 May 2018, and the input size is the whole point. Up to 10^5 commands means you can't reallocate the array on every append without it hurting. It's a dynamic array design problem: build a vector on a raw backing array, then answer append, get, set, pop, and size, returning one string per command. It looks like a warm-up, but the "no built-in resizable collection" rule trips people who reach for a list out of habit. If you blank on the growth logic during the live OA, StealthCoder is the safety net running invisibly on your screen.

The problem

Implement a vector with a manually managed backing array. Process parallel operations and arguments:
append [value]: add a value.
get [index]: return the value.
set [index,value]: replace a value.
pop []: remove and return the last value.
size []: return the current size.
Return one string per command, using "null" for append and set. Grow the backing capacity geometrically; do not use a built-in resizable collection for stored elements.

Function
runDynamicVector(operations: String[], arguments: int[][]) → String[]

Examples
Example 1
operations = ["append","append","get","set","pop","size"]
arguments = [[4],[7],[0],[0,9],[],[]]
return = ["null","null","4","null","7","1"]
The set changes the remaining first value to 9 after pop removes 7.

Constraints
At most 10^5 commands.
Indices and pop operations are valid.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is geometric growth. Keep a fixed-size array, a capacity, and a size counter. On append, if size equals capacity, allocate a new array of double the capacity, copy the elements over, then write the value. That gives amortized O(1) appends. Get and set are direct index access. Pop returns the element at size-1 and decrements size, so you don't need to clear anything. Size just returns the counter. The common pitfalls are growing by a fixed amount, which goes quadratic, starting with capacity 0 and then doubling to 0, and formatting output wrong. Append and set must emit the string "null", and the numbers must be converted to strings. Walk Example 1 by hand before you submit. Remember that set after pop hits the remaining first element. If the resize code slips on the live OA, StealthCoder can hand you a clean version fast.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Implement a Dynamic Array Vector 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Bloomberg reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Implement a Dynamic Array Vector FAQ

How hard is the Bloomberg dynamic array vector problem really?+

Easy on algorithm, easy to fumble on details. There's no clever trick beyond doubling capacity. Most lost points come from the resize edge case, the "null" strings for append and set, or accidentally using a built-in list for storage.

What's the trick to passing 10^5 commands?+

Double the capacity when the array is full. Copying n elements only happens occasionally, so appends average out to O(1). Growing by a constant amount makes the total work quadratic, which is what the input size is designed to punish.

Can I use a built-in list or ArrayList for storage?+

No. The statement says not to use a built-in resizable collection for stored elements. Use a plain fixed-size array and manage capacity yourself. A list or vector for the output strings is fine, since that isn't the stored data.

How do I handle the output format?+

Return one string per command. Append and set give "null". Get and pop give the number converted to a string. Size gives the counter as a string. Build the result in order as you loop over operations and arguments together.

How do I prepare for this in 48 hours?+

Write a vector class from scratch once, with append, pop, get, set, and a resize method. Test it on Example 1 and on a run of many appends. Then confirm your pop doesn't shrink or break capacity logic. That covers nearly everything this problem tests.

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