Problem · Math
Double-Base Palindromes
Learn this problemProblem statement
Given an integer upperBound, return every integer x such that 1 <= x <= upperBound and the ordinary representations of x in both base 10 and base 2 read the same forward and backward.
Binary representations must not contain leading zeroes. Return the qualifying integers in increasing order.
Function
doubleBasePalindromes(upperBound: int) → int[]Examples
Example 1
upperBound = 20return = [1,3,5,7,9]For example, 9 is 9 in decimal and 1001 in binary, so it qualifies. No integer from 10 through 20 is palindromic in both bases.
Example 2
upperBound = 100return = [1,3,5,7,9,33,99]33 is 100001 in binary, and 99 is 1100011; both representations are palindromes.
Constraints
1 <= upperBound <= 100000.- Use each number's canonical decimal and binary representations without leading zeroes.