Karan and Trees

4.1

8 votes
Tree, Basic Programming, Easy, Binary Tree, Open, Approved
Problem

Karan performed poorly in the Capillary Java Hiring Challenge because he did not know the concept of trees. After the contest, he asks you to help him out in the questions.

Given two nodes of a binary tree, you need to tell the lowest common ancestor.

The root node is 1 and the general form of left node is 2n and of right node is 2n+1, where n is the parent.

Input:

The first line contains the number of test cases T. Each test case contains two space separated integers, the nodes.

Output:

The Lowest Common Ancestor, one per line.

Constraints:

1 <= T <= 1000

1 <= a,b <= 10^18


This is the last question in the contest. Hope you had a great time!!! Keep practising :)


Thanks to Sri Patel for pointing out the language problem in the statement. Any inconvenience is regretted.

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?