Reported October 2026
Bloomberghash table

Sparse Vector and Matrix Operations

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 reportedly served this sparse vector and matrix question in October 2026, and the trap is the zero. Set an entry to 0 and it has to vanish from storage, in the vector and in both matrix views. Miss that once and every later DOT is wrong. The hinted pattern is breadth-first-search, but nothing here traverses a graph. It's hash maps and careful bookkeeping. If you blank mid-assessment, StealthCoder is a desktop overlay the proctor can't see, and it can hand you the structure in real time.

The problem

Maintain one sparse vector and one sparse matrix. Unset entries are zero, and setting an entry to zero removes it from sparse storage. Process these commands:
VSET index value, VGET index.
VDOT k i1 v1... ik vk: dot the stored vector with the supplied sparse vector of k distinct index-value pairs.
MSET row column value, MGET row column.
RDOT row k i1 v1... ik vk: dot one stored matrix row with a supplied sparse vector over columns.
CDOT column k i1 v1... ik vk: dot one stored matrix column with a supplied sparse vector over rows.
Return the results of GET and DOT commands in order. Store the matrix with synchronized row and column sparse views.

Function
processSparseOperations(vectorLength: int, rowCount: int, columnCount: int, operations: String[]) → long[]

Examples
Example 1
vectorLength = 1000000
rowCount = 1000
columnCount = 1000
operations = ["VSET 5 7","VSET 20 -2","VGET 5","VDOT 3 5 4 6 9 20 3","MSET 2 5 10","MSET 2 8 -1","MGET 2 8","RDOT 2 2 5 3 8 4","CDOT 5 2 2 6 9 7"]
return = [7,22,-1,26,60]
The vector dot is 7×4 + (-2)×3 = 22. Row 2 dots to 10×3 + (-1)×4 = 26, and column 5 contributes 10×6 = 60.
Example 2
vectorLength = 10
rowCount = 10
columnCount = 10
operations = ["VSET 1 5","VSET 1 0","VGET 1","MSET 3 4 9","MSET 3 4 0","MGET 3 4","RDOT 3 1 4 7","CDOT 4 1 3 7"]
return = [0,0,0,0]
Zero assignments remove both vector and synchronized matrix entries.

Constraints
1 <= vectorLength, rowCount, columnCount <= 10^9.
1 <= operations.length <= 50000.
All indices are in range; each sparse operand lists distinct indices and k matches its pair count.
Values are signed 32-bit integers. Every product, intermediate accumulated dot-product sum, and returned value fits a signed 64-bit integer.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Use a hash map for the vector, and a map of row to (column to value) plus a map of column to (row to value) for the matrix. Every MSET writes to both views. If the value is 0, delete from both, and delete the inner map if it ends up empty. That's the edge case that breaks naive solutions: a stale entry in one view makes CDOT disagree with RDOT. For a DOT, loop over the supplied k pairs and look each index up in the stored map. That costs O(k) per query, not O(stored size). Accumulate in a 64-bit integer, since products exceed 32 bits. Don't allocate arrays of size vectorLength or rowCount, because those go up to 10^9. Missing keys count as zero. If you freeze on the dual-view sync, StealthCoder is the hedge during the live OA.

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 Sparse Vector and Matrix Operations 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.

Sparse Vector and Matrix Operations FAQ

What's the trick in this Bloomberg sparse operations problem?+

Store only nonzero entries in hash maps, and treat assigning zero as a delete. For the matrix, keep a row view and a column view and update both on every MSET. The dot products then iterate over the supplied pairs and look up each index, so cost depends on k.

Why is breadth-first-search listed as the pattern?+

It's a loose tag. Nothing in the commands involves traversing nodes or levels. The real work is hash-map design and keeping two views consistent. Don't spend prep time on BFS for this one.

What breaks a naive solution?+

Allocating dense arrays fails because dimensions reach 10^9. Forgetting to remove zeroed entries from both matrix views gives wrong RDOT or CDOT results. Using 32-bit ints for sums overflows. Use 64-bit for every product and accumulator.

How do I handle MGET and VGET on unset entries?+

Return 0 when the key isn't in the map. Don't insert on read. If you use a default-inserting map access, you'll quietly create zero entries and break the sparse invariant.

How do I prepare in 48 hours?+

Write the solution once from scratch with nested hash maps, then run both examples by hand. Test the zero-removal case from Example 2 specifically. Check that your parser handles variable-length operands for the DOT commands, since k changes per line.

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