LeetCode 483, Hard. Topics: Math, Binary Search. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 32 parametrized pytest cases, and a playground notebook:
Problem
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 base k are 1’s.
Examples
Constraints
- n is an integer in the range [3, 10^18]
- n does not contain any leading zeros.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026