My code is correct but producing slightly wrong result..could you please tell why

question :

maximum frequency character

answer:

ch = str[i] would come inside the if condition