Yesterday there was a online test of some website (GeeksforGeeks) where I encountered the below problem, I was not successful in getting AC for the problem because of TLE issue, it will be very help if someone can share the approach or give hints to solve the problem ,below I am attaching the problem statement. My time complexity of the solution was O(N.x) where 'x' is the frequency of maximum element of the given array. Any help would be appreciated.