According to the question, you have to give the prefix which has occurred the most number of times and if there are two prefixes of the same count, you have to output the biggest one.
I think your code isn’t working because you are only taking the 2nd occurrence of the first letter (s[0]) and checking it with the first few letters of the string one by one.
Instead, you must start with the biggest substring till the second occurrence of the first letter (not including it) and get the count of that substring with the whole string and see if it matches n//countn.
Eg: Take the string ‘THYTH’. Get the first letter count, which is 2. Divide that with the total letters, which is 5//2=2. Start from s[0…2]=‘TH’. Get the count of ‘TH’ in the string, which is 2. This matches our previous floor division value. Hence, ‘TH’ is the required prefix. If it doesn’t match, go to s[0…1] and so on.
I hope I have cleared your doubt. Since, I don’t code C++, please check my Python implementation
@aadarsh_ram , Thanks man. The problem with my code was that I was not tracking all the occurrence of a 1st character in the string for getting the biggest string. Here is the passed solution: CodeChef: Practical coding for everyone