Reported September 2022
Bloomberghash table

Find the Root 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 Bloomberg OA reported in September 2022 hands you a tree, but you never have to traverse it. Everything hinges on a plain hash set, or even a sum, over the child lists. You get process IDs and their children in random order, and you need the one ID that's nobody's child. It looks like a tree problem and it's really a counting problem in disguise. If you've got an invite in your inbox, this one's quick once you see it. And if you blank under the clock, StealthCoder runs invisibly on your desktop as a safety net during the live OA.

The problem

processIds[i] is a process ID and children[i] lists its child process IDs. The rows are in arbitrary order and together form one rooted tree.
Return the root process ID.

Function
findRootProcess(processIds: int[], children: int[][]) → int

Examples
Example 1
processIds = [5,1,4,3,6,2]
children = [[],[2,3],[],[6],[],[4,5]]
return = 1
Every ID except 1 appears as a child.

Constraints
1 <= processIds.length <= 10^5.
children.length == processIds.length.
Process IDs are unique and every child ID appears in processIds.
The relationships form one rooted tree.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick: the root is the only process ID that never appears in any children list. Put every child ID into a set, then scan processIds and return the one missing from it. That's O(n) time and O(n) space. There's a slicker version. Sum all process IDs, subtract the sum of all child IDs, and the difference is the root. That's O(1) extra space, and it works because every non-root ID appears exactly once as a child. The common pitfall is building the tree with parent pointers and doing DFS, which wastes time and invites bugs on 10^5 nodes. Another is assuming processIds is ordered or that index 0 is the root. The rows are in arbitrary order, so don't rely on position. Watch the integer overflow risk in other languages if you use the sum approach. If you freeze during the live OA, StealthCoder can surface this in seconds.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Find the Root 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find the Root Process FAQ

How hard is Find the Root Process really?+

Easy once you spot it. There's no traversal needed. The root is the only ID that never shows up as a child, so one pass to collect children and one pass to find the missing ID solves it. Most of the difficulty is overthinking the tree.

What's the trick to solving it fast?+

Ignore the tree structure. Build a set of every ID found in the children lists, then return the process ID that isn't in it. Alternatively, subtract the sum of all child IDs from the sum of all process IDs. Both are linear.

Do I need DFS or BFS for this?+

No. Traversal is unnecessary because you're not asked to visit nodes or compute depth. You only need the node with no parent. Building adjacency and walking it costs extra code and extra risk for the same answer.

What are the edge cases to check?+

A single process with an empty children list should return that ID. Also confirm you don't assume the root is first or that IDs are sorted, since rows come in arbitrary order. Constraints guarantee one valid rooted tree, so no need to handle multiple roots.

How should I prepare for this in 48 hours?+

Practice the pattern of finding the node with in-degree zero using a set or a sum trick. Write it once in your language, check complexity is O(n), and then move on to other tree and hash set problems Bloomberg might reuse.

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