The code does not stops running

I dry runned the code but there seems to be no problem. But on compiler it it does not show the final result and goes on infinite loop (just assuming not sure ). Please point out the mistake

hello @S_yajur
pls share ur code using cb ide.
i will check

here is the link:

@S_yajur
check now->

u can use map in place of running this brute force to compute frequency

can u please explain as to why after puttting i=j; line out of the loop, the code runs fine

puttting i==j inside loop is risky becuase this updation will happen only when loop will run and that else block will run .
what if the loop dont run or else never execute . in such case i will never update and hence it will stuck in infinite loos

can u give an example where this scenario will take place? Wont it depend from testcase to test case?

yeah … it will depend on test case only.

you can pick any test case of this problem (from solution section)in which it is giving tle.

yes I tried the test cases and found out why i=j should be outside ‘if’ statement, but it is only for test cases like “aa”, but in test cases like “helloworlld” while dry running it works fine, but when I run the code, after taking the input it keeps on running and does not return anything. Why is this happening?

As u can see i have to CTRL +C to get out the program.

@S_yajur

for cases lik aa , ur i never get updated (do dry run to validate this)
and due to which which loop condition always remain valid hence it is runing infinitely

yup, for aa i is not getting updated, but wat about testcases like “Hello World”?

bro just dry run na for the same case.
also one thing keep in mind that the else is not a part of else

Please explain in detail how map can be used to solve this problem.

@S_yajur
use map to store frequency of each character.
and then use that map to find the character with maximum frequency

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.