Reported October 2022
Bloomberghash table

Kill Process

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

The mistake that sinks a first attempt on Bloomberg's Kill Process is scanning the whole ppid array for children every time you kill something. That turns a simple tree walk into a slow nested loop. Bloomberg candidates reported this one in October 2022, and it's a clean tree traversal wearing a process-list costume. You get parallel arrays, a kill target, and you return every descendant ID in ascending order. If you blank on the setup during the live OA, StealthCoder runs invisibly on your screen as a safety net. Know the shape of the solution first, though, because it's short.

The problem

pid[i] is a process ID and ppid[i] is its parent ID; parent ID 0 denotes a root.
Killing process kill also kills every descendant. Return all killed process IDs in ascending order.

Function
killProcess(pid: int[], ppid: int[], kill: int) → int[]

Examples
Example 1
pid = [1,3,10,5]
ppid = [3,0,5,3]
kill = 5
return = [5,10]
Process 10 is a child of 5.
Example 2
pid = [1,2,3]
ppid = [0,1,1]
kill = 1
return = [1,2,3]
Killing the root kills both children.

Constraints
pid.length == ppid.length.
Process IDs are unique and relationships form a forest.
kill appears in pid.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is to build a hash map from parent ID to a list of child IDs in one pass over the arrays. Then run DFS or BFS from the kill ID, collecting every node you visit. That's O(n) time and space. The common pitfall is rescanning ppid for each node, which gives O(n^2). The second pitfall is the output order. The examples show ascending order, so sort the collected IDs before returning, even though traversal order won't match. Don't forget the kill node itself belongs in the result. Parent ID 0 only marks roots, so never treat 0 as a real process. Since the input is a forest, you don't need a visited set, but adding one costs nothing. If the adjacency-map idea slips away under pressure, StealthCoder is the hedge on the live OA. It reads the problem and hands you the pattern.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Kill Process 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 for the candidate who got the OA invite this morning and has 72 hours, not six months.

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 for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Kill Process FAQ

How hard is Kill Process really?+

It's easy to medium. The logic is a tree traversal, and the only real work is converting parallel arrays into a parent-to-children map. If you've written a BFS or DFS before, you can finish it in a few minutes.

What's the trick to Kill Process?+

Build a hash map from each parent ID to its list of children in a single pass. Then traverse from the kill ID and collect everything you reach. This avoids rescanning the arrays for every node, which is the slow approach.

Do I need to sort the result?+

Yes. The problem asks for killed IDs in ascending order, and DFS or BFS won't produce that on its own. Collect the IDs, then sort once at the end. Sorting costs O(k log k) where k is the number of killed processes.

Should I use DFS or BFS?+

Either works. BFS with a queue avoids recursion depth issues on a long chain of processes. DFS is shorter to write recursively. Pick the one you can write without bugs, since the result gets sorted anyway.

How do I prepare for this in 48 hours?+

Write it once from scratch: build the map, traverse, sort. Then do the same for two other tree-from-arrays problems so the map-building step feels automatic. Bloomberg reported this in October 2022, so expect similar graph and tree basics.

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