educative.io

Educative

Why don't use HashSet here?

The HashMap here is counting the occurrence of each integer, which we do not need.
The HashSet would be enough.

1 Like

I had the same question as well. We think alike my friend.

Hi Jo_wang and Raviteja_Lokineni,
HashMap Stores elements in form of key-value pair i.e each element has its corresponding key which is required for its retrieval during iteration. HashSet stores only objects no such key value pairs maintained. … HashSet is completely based on object so compared to hashmap is slower.
Here we use hashmap because we need key value pair, in key we store the element and in value we store the number of occurrences of that element so here hashset is not enough.

Hi Kanwal_Saeed
Could you please send me the link to the original solution page that I could review it again, now I’ve received your detailed explanation yet I couldn’t find the page so I don’t even know what kind of a problem it is? It’s been too long since I last reviewed the course.