My code does not work as expected

This is my code:

It gives wrong answer please help me find the problem in the code

I don’t have access to the question, but one mistake that I can clearly see is that you probably are not resetting the freq[] array after each test case.