Help in WEIRDO problem (TLE in small testcases)

Hey everyone

My code for WEIRDO is giving TLE for short test cases and it passes long test cases. I couldn’t find the reason for it.
Can anyone help me with this?
Link to the problem: Problem

Link to my Solution: My Solution
Other submissions

Any test cases where my code is failing or bug will be a great help.
Edit1: I tried with changing map to unordered_map and with sorting it is still the same. Link: Updated code

same happened with me. Apparently using vector instead of map would solve the issue!

1 Like

Maybe it is because you are using map while calculating for which string is Alice and Bob. You can replace that with a 26 size array for each character.
Also, for each string you storing frequencies to calculate in a map, that can also be done with arrays.
Here in map for each access time will be O(logN), while in array it’s O(1).
Maybe that’s the reason you are getting TLE.

I just replaced the l <= 10 case with original bruteforce for 30 points

But I am confused as it passed the long testcases and not passing small testcase when L<=10 and |S|<=10. I feel strange about passing long cases and TLE on small cases.
I will also try your approach. Thanks.

1 Like

I even tried with unordered_map still it didn’t pass.