FastPrepFind the Root Process

Find the Root Process

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

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.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int findRootProcess(int[] processIds, int[][] children) {
  // Write your code here.
}
processIds[5,1,4,3,6,2]
children[[],[2,3],[],[6],[],[4,5]]
expected1
Checking account…