Last 2 test cases lead to TLE

@varun.saxena your program is logically correct. I made some changes in your code https://ide.codingblocks.com/s/253556 it will pass all the test cases. (I think using the count function in each iteration and the if else blocks increased the complexity, and if the map is a global variable, then it is not in the stack memory, that too plays a part) If the constraints are too tight, as is the case in this question, it will give TLE

I noticed that for the map you directly access the elements and incremented it by 1.
Wouldn’t the map[val] initially contain a garbage value until we initialize it?

@varun.saxena no that way works too, it will not give garbage value. (we have not pre-allocated any space for that val, so it wont contain garbage value)