# LOOTCASE

Posted: 11 Mar, 2021
Difficulty: Moderate

## PROBLEM STATEMENT

#### Example:

``````‘L = 1’ and  ‘R = 15’ so between these numbers prime numbers lie are - {2, 3, 5, 7, 11, 13}. As you can see ‘11’ has two ‘1s’ and ‘13’ has one ‘1’ so the frequency of ‘1’ is ‘3’ which is maximum hence our answer is ‘1’.
``````
##### Note:
``````Both 'L' and 'R' are exclusive.
``````

#### Input Format:

``````The first line of input contains a ‘T’ number of test cases.

The first line of each test case contains two space-separated integers ‘L’ and ‘R’ denoting the range.
``````

#### Output Format:

``````For each test case, return the number with the highest frequency. In case more than one number has a maximum frequency, then return the number with the highest value. In case no prime number lies in between the given range return as ‘-1’.
``````
##### Note:
``````You are not required to print anything explicitly. It has already been taken care of. Just implement the function.
``````

#### Constraints:

``````1 <= T <= 10
1 <= L <= R <= 10^3

Time Limit: 1 second
``````
Approach 1
• First, we find out the prime numbers by simply running a loop between our range ‘L’ and ‘R’ by checking the number is prime or not.
• If the number is prime :
• Now for every prime number, we store the count of each digit by separating the digit from the number.
• We use an array ‘ARR[]’ for storing the count of the number like we have to only consider {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} these digits.
• After checking for every number
• Now we simply find out the digit from this ‘ARR[]’ which has the highest frequency in case of tie largest digit is our answer.
• In the end, return the maximum frequency digit.