Numbers having alternate bits
Basic Accuracy: 64.56% Submissions: 79 Points: 1

Given a positive integer n. The task is to check whether this integer has an alternate pattern of 0 and 1 in its binary representation or not.
NOTE: Return 1 if the integer has alternate 0 and 1 in its binary representation else return 0.
 

Example 1:

Input: n = 12
Output: 0 
Explanation: n = 12 = "1100" 
Hence there is no alternate pattern.

Example 2:

Input: n = 10
Output: 1
Explanation: n = 10 = "1010".
Hence n has an alternate pattern.


Your Task:  
You dont need to read input or print anything. Complete the function bitsAreInAltOrder() which takes n as input parameter and returns 1 if the integer has alternate 0 and 1 in its binary representation else return 0.

Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)

Constraints:
1<= n <=1015

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.

Output Window