A hypothetical chain of processes is represented as a tree. Processes are numbered starting at 1, incremented by 1. Every process spawns a number of processes equal to its process number. The first node, processNumber 1, spawns 1 process, the second spawns 2 and so on. Given a process number, find the process number of its parent.
processNumber = 6
From the diagram, the parent of 6 is 3.
graph TD
1 --> 2
2 --> 3
2 --> 4
3 --> 5
3 --> 6
3 --> 7
Complete the findParent function in the editor below.
findParent has the following parameter(s):
- int processNumber: the process number to query
int: the process number of the parent
$2 \leq \text{processNumber} \leq 10^9$
STDIN → Function
6 → processNumber = 6
3
Refer to the graph in the problem statement. The child of 1 is 2. Children of 2 are 3 and 4. The children of 3 are 5, 6, and 7. Therefore, the parent process of the given process 6 is 3.