Given a non-negative integer n, return the count of prime numbers strictly less than n. A prime number is a number greater than 1 that has no divisors other than 1 and itself. Return 0 for null input or for n <= 2.
Examples:
Input: n = 10
Output: 4
Explanation: The primes below 10 are 2, 3, 5, 7
Input: n = 0
Output: 0
Explanation: No primes exist below 0
Input: n = 1
Output: 0
Explanation: No primes exist below 1
Input: n = 2
Output: 0
Explanation: No primes exist strictly less than 2
Input: n = 20
Output: 8
Explanation: The primes below 20 are 2, 3, 5, 7, 11, 13, 17, 19
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay September 2026 (Sep 1–15)Sponsored by FLXBL
Contest runs September 1 - 15. Complete challenges to climb the leaderboard!
1st & 2nd: Salesforce certification exam voucher — see all prizes
Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.