Count Primes (Sieve)
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Given a non-negative integer n, return the count of prime numbers that are **strictly less than** n.
A prime number is an integer greater than 1 whose only positive divisors are 1 and itself. For example, 2, 3, 5, and 7 are prime, while 1, 4, and 9 are not.
Your goal is to count how many primes fall in the range [2, n - 1]. A naive approach that tests each candidate for primality individually will work but can be slow for large n; aim for an approach that scales well as n grows (the Sieve of Eratosthenes is ideal here).
Examples
Constraints
- `0 <= n <= 5 * 10^6`
- The answer fits in a 32-bit signed integer.
- The function must handle `n = 0` and `n = 1` by returning `0`.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.