Count the frequency in the array

question–>
https://practice.geeksforgeeks.org/problems/frequency-of-array-elements/1/?undefined#
code–>


when iam using array the code is working fine but when i use a map it give TLE why?


M.find() complexity is log(n) and you are checking it n times , so it makes it nlog(n) , moreover we need to solve it in O(n) complexity. That’s why you are getting TLE but right answer.

If this solves your doubt, please mark it as resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.