As mentioned by @wolf, your method get_least_count_key
is not efficient enough and will result in Time Limit Exceeded, but that is another problem.
You are returning min_key
inside the for loop. What if you are not in the for loop? Then you are not returning anything, and this is bad because this results in undefined behavior.
In your specific case, when you are not returning anything C++ just happen to return a random integer value for you, which is some arbitrary large number. This ends up outputting more characters than it should be, resulting in Output Limit Exceeded.