Maximum 0’s between two immediate 1’s
Easy Accuracy: 34.9% Submissions: 1188 Points: 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​

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.