Palindromic Binary Representation InterviewBit Solution
Problem: Palindromic Binary Representation
Problem Description
Given an integer A find the Ath number whose binary representation is a palindrome. NOTE
Consider the 1st number whose binary representation is a palindrome as 1, instead of 0
Do not consider the leading zeros, while considering the binary representation.
Problem Constraints
1 <= A <= 2104
Input Format
The first and only argument is an integer A.
Output Format
Return an integer denoting the Ath number whose binary representation is a palindrome.
Example Input
Input 1: A = 1 Input 1: A = 9
Example Output
Output 1: 1 Output 2: 27
Example Explanation*
Explanation 1:
1st Number whose binary representation is palindrome is 1
Explanation 2:
9th Number whose binary representation is palindrome is 27 (11011)
Solution Approach:
Solution in C++:
If you have any questions or queries, feel free to drop a comment in the comments section below.
Note: Help us improve this blog
If you have a better solution, and you think you can help your peers to understand this problem better, then please drop your solution and approach in the comments section below.
We will upload your approach and solution here by giving you the proper credit so that you can showcase it among your peers.
Comments