3/4 test case passed. What am i not considering?

import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
int[] freq = new int[26];
char[] c = str.toCharArray();
int n = c.length;
for(int i=0;i<n;i++)
{
if(c[i]!=’ ')
{
freq[c[i]-‘a’]++;
}
}

	StringBuilder sb = new StringBuilder();
	char cc=0;
	for(int i=0;i<n;i++)
	{
		if(i==0)
		{
			cc=c[i];
			sb.append(c[i]);
			if(freq[c[i]-'a']>1)
			{
				sb.append(freq[c[i]-'a']);
			}
		}
		else if(cc!=c[i])
		{
			cc=c[i];
			sb.append(c[i]);
			if(freq[c[i]-'a']>1)
			{
				sb.append(freq[c[i]-'a']);
			}
		}	
	}

	String a = sb.toString();
	System.out.println(a);
}

}

Your code should fail for cases where a character has two ranges of occurences in the same string. For eg. for the string “aaabbaa” your code should print wrong answer.

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.