Failing test case 1 and 2, pls help me correct them

Hey, It is not so that the string is in lexicographically increasing order

So
for(int i=0;i<26;i++)
{
if(freq[i]!=0)
{
char ch=i+‘a’;
cout<<ch<<freq[i];
}

}

This logic would not be correct.
HINT:
Print the character then its frequency when u are traversing.

1 Like

i have corrected my code for non increasing but still test case 1 and 2 is failing

hey @shahnawaz again you are doing wrong,compression means you have to only compress consecutive chars not every occurrence of characters for ex aabbaa should be a2b2a2 but you are printing a4b2 which is wrong .
refer to this code for help(https://ide.codingblocks.com/s/179264) you will understand.

1 Like

okay, i will correct the code and try again

ok and let me know if you still faces any problem.

1 Like

Hey, your code fails for test casess like
abbbacdd

the answer shoudl be a1b3a1c1d2
But your code produces a2b3c1d2

THIS IS THE CORRECT CODE:
In case of any doubt please ask