We use cookies (including Google cookies) to personalize ads and analyze traffic. By continuing to use our site, you accept our Privacy Policy.

Strictly Palindromic Number

Number: 2481

Difficulty: Medium

Paid? No

Companies: Google, Amazon


Problem Description

Determine whether a given integer n is strictly palindromic. An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the representation of n in base b is a palindrome. A string is palindromic if it reads the same forward and backward.


Key Insights

  • For n >= 4, mathematical analysis shows that there is always at least one base in the range [2, n-2] where n's representation is not palindromic.
  • Specifically, n in base (n-2) is always represented as "12" (since n = (n-2) + 2), which is not a palindrome.
  • Thus, no integer n with n >= 4 can be strictly palindromic.
  • The solution directly returns false without needing to perform any base conversions.

Space and Time Complexity

Time Complexity: O(1) Space Complexity: O(1)


Solution

The key observation for this problem is that any integer n (with n >= 4) will have at least one base (specifically b = n-2) in which its representation is not a palindrome. When converting n to base (n-2), the result is always "12" because n = (n-2)*1 + 2. Since "12" is not palindromic, n cannot be strictly palindromic. Therefore, the solution is to simply return false for any valid input n.

Data structures: No additional data structures are needed. Algorithmic approach: Direct observation and mathematical reasoning avoid unnecessary computations.


Code Solutions

# Python solution with inline comments

def is_strictly_palindromic(n: int) -> bool:
    # For any n >= 4, it has been proven that n is not strictly palindromic.
    return False

# Example usage:
# print(is_strictly_palindromic(9))  # Expected output: False
← Back to All Questions