Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Count Binary Palindromic Numbers

XPChallenge Points: 30
levelLevel: Hard

You are given a non-negative integer n.
A number is called binary-palindromic if its binary representation (without leading zeros) reads the same forward and backward.
Your task is to return the count of all numbers k such that:
0≤k≤n
and the binary representation of k is a palindrome.
Note: The number 0 is considered binary-palindromic, and its binary form is "0".

Example 1:

Input: n = 12

Output: 6

Example 2:

Input: n = 4

Output: 3

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result