Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

200. Count Primes

MediumDay 59 of 60Bit Manipulation & Math

Given an integer n, return how many prime numbers are strictly less than n. A prime is a number greater than 1 whose only divisors are 1 and itself.

Example 1
Input: n = 10
Output: 4
The primes below 10 are 2, 3, 5 and 7.
Example 2
Input: n = 0
Output: 0
Constraints
  • 0 <= n <= 5 * 10^6
Hints
Frequently asked at: Amazon, Microsoft, Apple, Zoho
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min