dsa6 min read
Sieve of Eratosthenes — Generate All Primes Up to N in O(n log log n)
LC 204 Count Primes is the gateway sieve problem at Google and Amazon. Master the Sieve of Eratosthenes, understand why you start marking at p*p, and apply the technique to interval queries, prime factorization, and every sieve variant an interviewer can ask.
Read →