Google Singapore OA Question
Summer 2020 Internship
Interview on CoCubes
GCD (Greatest Common Divisor) of two positive integers is the largest positive integer that divides both numbers without a remainder.
Siblings: Nodes with the same parent are called siblings.
Level of a tree: Level of a tree is the number of edges on the longest path from the root node to a leaf.
You are given nodes of a binary tree of leven n as input.
Caluclate the GCD of each pair of siblings and then find the max & min GCD among them. Print the difference of max & min GCD ( max GCD - min GCD)
The input is in the following format:
1st line contains level 0 nodes. (i.e. root node).
2nd line contains nodes for level 1.
3rd line contains nodes for level 2 and so on.
Each node is represented by an integer value. Node value of -1 denotes an empty node(no node present at that place).
A single integer i.e., the difference of max & min GCD (max GCD - min GCD)