Given a positive integer n. The problem is to check if the number is Fibbinary Number or not. Fibbinary numbers are integers whose binary representation contains no consecutive ones.
Input : 10 Output : Yes Explanation: 1010 is the binary representation of 10 which does not contains any consecutive 1's. Input : 11 Output : No Explanation: 1011 is the binary representation of 11, which contains consecutive 1's.
Approach: If (n & (n >> 1)) == 0, then ‘n’ is a fibbinary number Else not.
Time Complexity: O(1).
- 1 to n bit numbers with no consecutive 1s in binary representation.
- Check if a number has bits in alternate pattern | Set 1
- Count strings with consecutive 1's
- Number of values of b such that a = b + (a^b)
- Check if elements of Linked List are present in pair
- Find triplets in an array whose AND is maximum
- Set the rightmost off bit
- Length of longest consecutive zeroes in the binary representation of a number.
- Program to find the N-th term of series 3, 5, 33, 35, 53…. | Set-2
- Print the number of set bits in each node of a Binary Tree
- Accolite Interview Experience (On-campus)
- Find bitwise OR of all possible sub-arrays
- Find bitwise AND (&) of all possible sub-arrays
- Rotations of a Binary String with Odd Value
- Hamming distance between two Integers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Mithun Kumar