Maximum 0’s between two immediate 1’s
Submissions: 1039   Accuracy:

34.53%

  Difficulty: Easy   Marks: 2

Given a number N, the task is to find the maximum 0’s between two immediate 1’s in binary representation of given n. Return -1 if binary representation contains less than two 1’s.

Examples:

Input : N = 47
Output: 1
as binary of N = 47 is 101111

Input : N = 549
Output: 3
as binary of n = 549 is 1000100101

Input : N = 1030
Output: 7
as binary of N = 1030 is 10000000110

Input : N = 8
Output: -1
as there is only one 1 in binary representation of 8.


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 an integer N.

Output:
For each test case in a new line print the required result.

Constraints:
1<=T<=100
1<=N<=10000


Example:
Input:

2
8
549

Output:
-1
3​

** 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.