Amazon interview question
Print every circular prime below one million
- Company:
- Amazon
- Type:
- Coding
- Difficulty:
- Medium
- Reported:
- November 18, 2026
Problem
Write a program that prints all circular primes below one million.
A circular prime is a prime number for which every rotation of its digits is also prime. For example, 197 is a circular prime because 197, 971 and 719 are all prime.
The solution below exposes circular_primes(limit), which returns all circular primes smaller than limit in increasing order, and prints them for limit = 1,000,000.
Example 1
Input: limit = 100
Output: 2 3 5 7 11 13 17 31 37 71 73 79 97
These are the 13 circular primes below 100; for instance 19 is excluded because 91 = 7 x 13.
Example 2
Input: limit = 1000000
Output: 55 numbers, from 2 up to 999331
The full list is printed one number per line.
Constraints
- The bound is one million.
Reported by candidates or drawn from publicly available sources, and rewritten in our own words. Pathwise Prep does not publish confidential assessment content. Report a concern