Strictly Palindromic Number

An integer n is strictly palindromic if, for every base b from 2 to n - 2 inclusive, the representation of n in base b is a palindrome. Given n, return true if it is strictly palindromic and false otherwise.

30:00

Strictly Palindromic Number
medium
Free written solution
Topics
Companies

An integer n is strictly palindromic if, for every base b from 2 to n - 2 inclusive, the representation of n in base b is a palindrome. Given n, return true if it is strictly palindromic and false otherwise.

Example 1:
Input: {"n":9}
Output: false
Constraints:
  • 4≤n≤1054 \leq n \leq 10^5

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"n":9}

n = 9 must read the same forwards and backwards in every base from 2 to 7. Try the bases one by one.

n = 9 written in each base (2 to 7)

No base written yet.

the base that always breaks it

9 = 1 × 7 + 2, so in base 7:

1
2

1 ≠ 2

Variables
VariableValue
n9
bases2..7
DepthFunction Call
Stack empty
0/6