VOOZH about

URL: https://www.geeksforgeeks.org/dsa/fibbinary-numbers-no-consecutive-1s-binary-o1-approach/

⇱ Fibbinary Numbers (No consecutive 1s in binary) - O(1) Approach - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Fibbinary Numbers (No consecutive 1s in binary) - O(1) Approach

Last Updated : 15 Jun, 2022

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.
Examples : 
 

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.
 

Output : 
 

Yes


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

Comment
Article Tags:
Article Tags: