Strictly Palindromic Number — LeetCode 2396 Python Solution

MediumBrainteaserMathTwo Pointers
Problem
#2396
Reading time
2 min

The 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.

Example

Input
n = 9
Output
false
Explanation
In base 2: 9 = 1001 (base 2), which is palindromic.

Python solution

Python
class Solution:
    def isStrictlyPalindromic(self, n: int) -> bool:
        return False

Complexity

MeasureComplexity
TimeO(1)
SpaceO(1) auxiliary

Pattern: Two Pointers

Use the order already in the input to discard half the search space at every step. LeetCode 2396. Strictly Palindromic Number is filed here because LeetCode tags it Two Pointers, which is the vocabulary this hub collects.

The two pointers guide has the Python template for the pattern and the 201 LeetCode problems that use it.

Related problems

Frequently asked questions

How hard is LeetCode 2396. Strictly Palindromic Number?
LeetCode 2396. Strictly Palindromic Number is rated Medium on LeetCode.
What is the time complexity of LeetCode 2396. Strictly Palindromic Number?
The Python solution on this page runs in O(1).
What is the space complexity of LeetCode 2396. Strictly Palindromic Number?
The Python solution on this page uses O(1) auxiliary space.
What topics does LeetCode 2396. Strictly Palindromic Number cover?
LeetCode 2396. Strictly Palindromic Number is tagged Brainteaser, Math and Two Pointers on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity — invisible to screen sharing.

Get Stealth Interview