268. Count primes in range L to R

You are given an 2D array queries of dimension n*2.

The queries[i] represents a range from queries[i][0] to queries[i][1] (include the end points).

Return the count of prime numbers present in between each range in queries array.

Example 1:

Input : queries = [ [2, 5], [4, 7] ]

Output : [3, 2]

Explanation : The range 2 to 5 contains three prime numbers 2, 3, 5.

The range 4 to 7 contains two prime numbers 5, 7.

Example 2:

Input : queries = [ [1, 7], [3, 7] ]

Output : [4, 3]

Explanation : The range 1 to 7 contains four prime numbers 2, 3, 5, 7.

The range 3 to 7 contains three prime numbers 3, 5, 7.

Now Your Turn!

Pick the correct output for the given input

Input : queries = [ [1, 10], [10, 20] ]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= n <= 105
  • 1 <= queries[i][0] <= queries[i][1] <= 105

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution{
public:
vector<int> primesInRange(vector<vector<int>>& queries){
//your code goes here
}
};
Test Case

Input:

Queries