Print maximum frequency number in an array(with slight modification)

Revision en1, by ss_96, 2017-09-25 11:15:53

There is an integer array and 2 variables Q and M.The output required is the number which has the maximum frequency in the array, but the catch is that each number in the array can be increased/decreased by M and that too Q number of times.

In case of multiple answers print the first one.


array:1,2,3,4 and Q=1,M=1

Answer:3 ,as the array can be transformed into 2,2,2,4 (here 2 appears 3 times in this array, adding 1 in 1 and subtracting 1 from 3.)

A hashtable can be used here,but can't understand how to handle the addition and subtraction of each number of the array.

Can anyone please suggest an approach for that part?


Tags #c++, #algorithms, array, hashtable


  Rev. Lang. By When Δ Comment
en1 English ss_96 2017-09-25 11:15:53 726 Initial revision (published)