Circular Primes Below a Limit
Problem statement
A circular prime is a prime number whose every rotation of its digits is also prime. To rotate a number, move its first digit to the end; the rotations of 197 are 197, 971 and 719, and all three are prime, so 197 is a circular prime. A one-digit prime is a circular prime because its only rotation is itself.
The problem statement continues
ProExamples
Example 1
n = 100return = [2,3,5,7,11,13,17,31,37,71,73,79,97]- Every prime below 10 is circular, since a one-digit number has only itself as a rotation.
- 11, 13, 17, 31, 37, 71, 73, 79 and 97 are circular: for example 13 and 31 are both prime. 19 is not, because 91 = 7 × 13.
FastPrep Pro
Reported in 1 Amazon interview this weekUnlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$8.25/month
$99 billed yearly — or $19 month-to-month. Cancel anytime.
Free plan — 2 of 2 free unlocks used this week