Exist or not 628

i unable to find my mistake apart from this i m getting altough i have used only one loop

Hello @neeleshr628,

I would suggest you to use hashmap, as it requires O(1) searching time complexity.
As it can store negative values also, thus it will eliminate the if-else check.

Also, memory wastage can be prevented using hashmap.

Modify your code, and share if the error still persists.

Hope, this would help.
Give a like, if you are satisfied.

i have used the hash map but it was giving tle

You can refer to the following code:

It is using unordered hashmap.

if you don’t understand something, let me know.
Hope, this would help.
Give a like, if you are satisfied.

this is very lame but i found the solution basically we have to use first count function to check whether element is present or not but main part is we have to use array to store element and use array to store queries then use that array to find solution

@S19LPPP0208,

That’s surely a way to solve this question, by using a counter array/hashmap.
Can you please explain, why the problem is giving TLE for the approach he has used?

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.