Check Palindromic Digits in Every Required Base

Quick Overview

Determine whether a number is palindromic in every integer base from 2 through n minus 2, inclusive.

Check Palindromic Digits in Every Required Base

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem An integer `n` is strictly palindromic if its representation reads the same forward and backward in every integer base from 2 through `n - 2`, inclusive. Return whether `n` has this property. ```cpp class Solution { public: bool isStrictlyPalindromic(int n); }; ``` ### Examples **Example 1:** ```text Input: n = 5 Output: false Explanation: In base 3, five is 12, which is not a palindrome. ``` **Example 2:** ```text Input: n = 10 Output: false Explanation: In base 8, ten is 12, so one required base already fails. ``` ### Constraints - `4 <= n <= 100000`. ### Clarifying Questions - Must every required base work? Yes; one failure makes the answer false. - Is base `n - 2` included? Yes. - Which inputs are allowed? Integers from 4 through 100000. ```hint Check the boundary A universal condition can be disproved by one counterexample. ```

Overview: Determine whether a number is palindromic in every integer base from 2 through n minus 2, inclusive.

Google logo
Google
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

An integer n is strictly palindromic if its representation reads the same forward and backward in every integer base from 2 through n - 2, inclusive. Return whether n has this property.

class Solution {
public:
    bool isStrictlyPalindromic(int n);
};

Examples

Example 1:

Input: n = 5
Output: false
Explanation: In base 3, five is 12, which is not a palindrome.

Example 2:

Input: n = 10
Output: false
Explanation: In base 8, ten is 12, so one required base already fails.

Constraints

  • 4 <= n <= 100000 .

Clarifying Questions Guidance

  • Must every required base work? Yes; one failure makes the answer false.
  • Is base n - 2 included? Yes.
  • Which inputs are allowed? Integers from 4 through 100000.