Strictly Palindromic Number

An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic.

Given an integer n, return true if n is strictly palindromic and false otherwise.

A string is palindromic if it reads the same forward and backward.

Example 1
Inputn = 9
Outputfalse
In base 3, 9 is represented as 100, which is not palindromic, so 9 is not strictly palindromic.
Example 2
Inputn = 4
Outputfalse
Only base 2 is considered, and 4 is represented as 100, which is not palindromic.

Constraints

  • 4 <= n <= 10^5

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate