Hashmap solution

Can we use hashmap to check the frequency of each element and solve this question. That would be very short as compared to this solution?

@Shivam_Dureja HashMap has Average complexity of O(n). but you need to do this question in O(n)not average so we can use this algo.

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.