


Ninja is given an integer ‘N’. Ninja wants to find whether the binary representation of integer ‘N’ is palindrome or not.
A palindrome is a sequence of characters that reads the same backward as forward.
Ninja is busy with his training. Help Ninja in finding out whether the binary representation of ‘N’ is palindrome or not.
The first line contains a single integer ‘T’ representing the number of test cases.
The first and only line of each test case contains a single integer ‘N’ denoting the given integer.
Output format:
Return true if the binary representation of the given number is a palindrome. Else return false.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 100
1 <= ‘N’ <= 10^18
Time Limit : 1 sec
2
7
10
true
false
For the first test case :
The binary representation of 7 is 111. Hence it is a palindrome.
For the second test case:
The binary representation of 10 is 1010. Hence it is not a palindrome.
2
3
5
true
true
Compare the bits using a method similar to two pointers
The main idea is to compare bits from the left and right of the given number. If the i-th from left and right are the same move to the next bit else return false.
Algorithm:-
O(log2(N)) where ‘N’ is the given number.
We are iterating over all the bits of N and the total number of bits in ‘N’ is log2(N) +1. Therefore the time complexity is O(log2(N))
O(1)
We are using constant space