![]() |
VOOZH | about |
Given a positive integer n. The problem is to check whether only the first and last bits are set in the binary representation of n.
Examples:
Input : 9 Output : Yes (9)10 = (1001)2, only the first and last bits are set. Input : 15 Output : No (15)10 = (1111)2, except first and last there are other bits also which are set.
Approach: Following are the steps:
Output:
Yes
Time Complexity - O(1)
Space Complexity - O(1)