Strictly Palindromic Number - Problem

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.

Input & Output

Example 1 — Small Number
$ Input: n = 9
Output: false
💡 Note: In base 2: 9 = 1001 (palindromic), but in base 3: 9 = 100 (not palindromic), so return false
Example 2 — Very Small Number
$ Input: n = 4
Output: false
💡 Note: Need to check bases [2]. In base 2: 4 = 100 (not palindromic), so return false
Example 3 — Edge Case
$ Input: n = 2
Output: false
💡 Note: No bases to check (range [2, 0] is empty), but by definition return false

Constraints

  • 1 ≤ n ≤ 2 × 109

Visualization

Tap to expand
Strictly Palindromic Problem: Why It's ImpossibleInputn = 9Check all bases [2, n-2]Base 2: 9 = 1001 ✓Base 3: 9 = 100 ✗Base 4: 9 = 21 ✗Found non-palindromic!OutputfalseThe Challenge: Must be palindromic in ALL bases simultaneouslyFor n > 4, the base range [2, n-2] is too wideMathematical proof shows this constraint cannot be satisfied
Understanding the Visualization
1
Input
Given integer n = 9
2
Process
Must check palindrome property in bases 2 through 7
3
Output
Return false - impossible to satisfy all bases
Key Takeaway
🎯 Key Insight: The constraint is mathematically impossible to satisfy for any meaningful input
Asked in
Google 15 Meta 8 Amazon 12
15.0K Views
Low Frequency
~5 min Avg. Time
450 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen