Count Primes

Easy

Given an integer n, return the number of prime numbers strictly less than n.

Example 1

countPrimes()
Input
n = 10
Output
4

Why

2, 3, 5 and 7

Example 2

countPrimes()
Input
n = 0
Output
0
Constraints
0 <= n <= 5 * 10^6

Topics

MathArrays

Implement countPrimes in the editor and return the answer — printing it is never graded.