Highest Rating

3.2

15 votes
Arrays, Hash Maps, Hash Tables, Hiring, Medium
Problem

Neha and Jenish are good friends . Neha challenges Jenish to find the Highest possible Rating of given array A after applying some queries. According to Neha, Rating of an array is highest occourence of a element in the given array. Jenish is provided with the Magical Number M and Q . For Each element in the given Array A , Jenish can Perform Addition or Subtraction with M atmost Q times .

Since Jenish is so confused and not able to come out with the solution , Help him to find Highest Ratings Possible for Given Array after applying queries to each element.

Input :

  • First line of Input contains integer M
  • Second line contains integer Q
  • Third line contains integer N
  • Fourth line contains N elements representing elements of array A

Output :

  • Output the highest possible rating of array A after applying Queries.

Constraints :

  • 1N1000000
  • 1M100
  • 1Q10
  • 1Ai1000000
Sample Input
1
1
4
1 2 3 4
Sample Output
3
Time Limit: 1.5
Memory Limit: 256
Source Limit:
Explanation

Jenish can add 1 in 1st element and subtract 1 from 3rd element to get highest frequency of 2 , i.e. 3

Editor Image

?