In the following solution if I leave out mp.clear() and mp1.clear(), this gives TLE. If anyone could please explain me the difference between the two and why is it happening? And also when to use map.clear()?
For the first test case, map works just fine. But for the later test cases, the map contains all the data of previous test cases, which is obviously inefficient. That is the reason we tend to clear the map after each test case. Just like cleaning a plate before eating something in it.