A strictly palindromic number is a fascinating mathematical concept that challenges our understanding of number representations across different bases.
Given an integer n, we need to determine if it's strictly palindromic. This means that when we convert n to every possible base from 2 to n-2 (inclusive), the resulting string representation must be a palindrome in all of those bases.
What's a palindrome? A string that reads the same forwards and backwards, like "racecar" or "121".
Example: For n = 9, we'd check bases 2 through 7:
• Base 2: 9 = "1001" ✓ (palindrome)
• Base 3: 9 = "100" ✗ (not palindrome)
Since it fails in base 3, n = 9 is not strictly palindromic.
Goal: Return true if the number is strictly palindromic, false otherwise.
Input & Output
Visualization
Time & Space Complexity
O(n) bases to check, each base conversion takes O(log n), palindrome check takes O(log n)
Space needed to store the string representation in each base
Constraints
- 4 ≤ n ≤ 2 × 109
- The answer for all valid inputs will be false