Find the highest occurring digit in prime numbers in a range
Easy Accuracy: 25.56% Submissions: 1259 Points: 2

Given a range L to R, the task is to find the highest occurring digit in prime numbers which lie between L and R (both inclusive). If multiple digits have same highest frequency return the largest of them. If no prime number occurs between L and R, return -1.
 

Example 1:

Input: L = 2, R = 10
Output: 7
Explanation: Between 2 and 10 every digit
has same frquency and 7 is largest among
them.

Example 2:

Input: L = 2, R = 20
Output: 1
Explanation: Prime number between 2 and 20 are 
2, 3, 5, 7, 11, 13, 17, 19. 1 occur 
maximum i.e 5 times among 0 to 9.


Your Task:  
You dont need to read input or print anything. Complete the function maxDigit() which takes L and R as input parameter and returns the highest occuring digit. If multiple digits have same highest frequency return the largest of them. If no prime number occurs between L and R, return -1.

Expected Time Complexity: O(nlog(n)sqrt(n))
Expected Auxiliary Space: O(k)

Constraints:
1 <= L<= R <= 1000

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.


to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Find the highest occurring digit in prime numbers in a range

Output Window