Shortest distance in infinite tree
Submissions: 3082   Accuracy:

44.41%

  Difficulty: Easy   Marks: 2
Associated Course(s):   Sudo Placement 2019

Consider you have an infinite long binary tree having a pattern as below
               1
           2      3
        4  5    6  7
    .  .  .  .   .  .  .  . 
You are given two nodes with values x and y, the task is to find the length of the shortest path between the two nodes.

Input:
The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains two space separated integers x and y.

Output:
For each test case in a new line print the shortest length of the path from x to y.


Constraints:
1<=T<=1000
1<=x,y<=10^7

Example:
Input:

2
1 3
2 2
Output:
1
0


 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Shubham Joshi 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.