Smallest Good Base

Given an integer n represented as a string, return the smallest good base of n.

We call k >= 2 a good base of n if all digits of n in base k are 1's.

Example 1
Inputn = "13"
Output"3"
13 base 3 is 111.
Example 2
Inputn = "4681"
Output"8"
4681 base 8 is 11111.

Constraints

  • n is an integer in the range [3, 10^18].
  • n does not contain any leading zeros.

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate