Problem · Math

Parent Process Number

EasyIBMOA
See IBM hiring insights

Processes are arranged in a tree and numbered starting from 1 in the order they are created.

  • Process n creates exactly n child processes.
  • Child processes are numbered sequentially as they are created.

You are given a process number processNumber, where processNumber > 1.

Determine the parent process number of this process.

Examples
01 · Example 1
processNumber = 6
return = 3

Suppose processNumber = 6.

The source diagram highlights process 6 and its parent process 3:

2343567

Process 3 creates child processes 5, 6, and 7, so the parent process number of 6 is 3.

Constraints
  • 2 ≤ processNumber ≤ 10^9
More IBM problems
drafts saved locally
public int getParentProcessNumber(int processNumber) {
  // write your code here
}
processNumber6
expected3
checking account