My code is giving TLE for test case 2 (Exist or Not) - Hashing

How can I optimize the solution for Exist or Not problem?

My code:
https://ide.codingblocks.com/s/62811

Hi Anant, pls add one more condition in while loop in Line 26 which is q > -1
i.e. it should look like

while ( q-- && q > -1 ) {

It will work now :slight_smile:

Also I suggest,
instead of inserting a pair in map m just do this:

m[t]++ ;

and instead of using find in line 32 and 33 you can always do this:

if ( m[q] != 0 ) {

Thank you for the explanation!!