#K60927. Deepest Common Ancestor of Leaf Nodes in a Balanced Binary Tree
Deepest Common Ancestor of Leaf Nodes in a Balanced Binary Tree
Deepest Common Ancestor of Leaf Nodes in a Balanced Binary Tree
Given a balanced binary tree with (n) nodes, the leaf nodes are located at the deepest level. The task is to determine the deepest node that acts as the lowest common ancestor (LCA) of all the leaf nodes. More precisely, if the deepest level is (L) (where (L = \lfloor \log_2 n \rfloor)), then the required node is located at level (L-1) with position (0) (using 0-indexing for both level and position).
For example, if (n = 4), then (L = 2) and the answer is (1 0); if (n = 16), then (L = 4) and the answer is (3 0).
inputFormat
The input consists of a single integer (n), representing the total number of nodes in the balanced binary tree.
outputFormat
Output two integers separated by a space, where the first integer is the level and the second integer is the position of the deepest node that is the LCA of all leaf nodes.## sample
2
0 0
</p>