Check If Binary Representation of a Number is Palindrome

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.

Input format:
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.
Constraints:
1 <= ‘T’ <= 100
1 <= ‘N’ <= 10^18

Time Limit :  1 sec
CodingNinjas
author
2y

Check if binary conversion of given number is palindrome or not. Ex: 6 (0110) is palindrome.
I used a recursive function for binary conversion and then check for palindrome using a loop. Refrain from u...read more

CodingNinjas
author
2y
Bitmasking Approach

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

  • Create ...read more
Help your peers!
Add answer anonymously...
Nagarro Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter