• + 4 comments

    LOGIC ALERT :-

    you just have to find out the multiset which has the maximum number of elements that satisfies the condition given in the question. Now see if you pick up elements like ,say, { 4,4,5,5,6} , so it is not a valid multiset because if you'd find out the difference between 6 and 4 , it will be 2 which is again greater than 1. SO now analyse through number thoery that no three consecutive elements can have the difference equal to one among the one except they are two subsequent numbers . Let's analyse this from the above example . {4,4,5,5} can be a valid multiset ,{5,5,6} can be a valid one because in each multiset there are two subsequent numbers . In first , it is 4 and 5. In second 5 and 6. So you just have to find out the frequency of the TWO consecutive numbers . Take a static array say ar and start find the frequency of every element in the array (original ). Now you have the array ar which contains frequency of every element in the original array . You just have to find out the maximum frequency of the consequent elements .