• + 2 comments

    By problem statement itself, it's very clear that we need to worry about numbers that are adjacent or equal(i.e. absolute difference<=1). freq[] has got frequency of occurance of each element of input array. We just need to return which two adjacent elements appear highest in array.(sum of their frequencies)