Skip to interview prep
Apexed

76. Count Primes (Sieve of Eratosthenes)

MediumMiscellaneous

Return the number of prime numbers strictly less than n.

Example 1

Input: n = 10
Output: 4
Explanation: 2, 3, 5, 7

Constraints

  • 0 ≤ n ≤ 5 × 10⁶

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Count Primes (Sieve of Eratosthenes) — coding interview practice — Apexed