Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5642 |

@Quandray | 5233 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 4610 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3522 |

@sushant_a | 3459 |

@verma_ji | 3413 |

Complete Leaderboard | |

Handle | Score |

@sanskar94511 | 603 |

@akashverma4 | 363 |

@swastik8750 | 300 |

@nishunishuraj18 | 286 |

@surajmamgai | 264 |

@anks9013 | 222 |

@nayan2709 | 213 |

@burhanuddinbohra72 | 212 |

@realname | 203 |

@amank8975 | 203 |

@manmeetkaur18102000 | 202 |

Complete Leaderboard |

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

Login to report an issue on this page.

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

Yes
Find the highest occurring digit in prime numbers in a range

...