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).
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Fibbinary Numbers (No consecutive 1s in binary)
- 1 to n bit numbers with no consecutive 1s in binary representation.
- 1 to n bit numbers with no consecutive 1s in binary representation
- Length of the Longest Consecutive 1s in Binary Representation
- Binary string with given frequencies of sums of consecutive pairs of characters
- Length of longest consecutive zeroes in the binary representation of a number.
- Find consecutive 1s of length >= n in binary representation of a number
- Maximum number of consecutive 1's in binary representation of all the array elements
- Minimum flips in a Binary array such that XOR of consecutive subarrays of size K have different parity
- Count number of binary strings without consecutive 1’s : Set 2
- Count of binary strings of length N with even set bit count and at most K consecutive 1s
- Check if a number can be expressed as a sum of consecutive numbers
- Sum of Hamming difference of consecutive numbers from 0 to N | Set 2
- Check if a number has bits in alternate pattern | Set-2 O(1) Approach
- A backtracking approach to generate n bit Gray Codes
- Longest sub-sequence with a given OR value : O(N) Approach
- Gray to Binary and Binary to Gray conversion
- Meta Binary Search | One-Sided Binary Search
- Check if binary representations of 0 to N are present as substrings in given binary string
- Count strings with consecutive 1's
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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