What is the problem in my code 1 test case failed

import java.util.*;
public class Main {
static String check(String s) {
char[] arr = s.toCharArray();
int[] charcount = new int[26];
for (char c : arr) {
charcount[c - 97]++;
}

	StringBuilder sb = new StringBuilder();

	for (int i = 0; i < charcount.length; i++) {
		if (charcount[i] != 0) {
			char ch = (char) (i + 97);
			sb.append(ch);
			if (charcount[i] != 1) {
				sb.append(charcount[i]);
			}

		}
	}
	return sb.toString();
}

public static void main(String args[]) {
	Scanner sc = new Scanner(System.in);
	String s = sc.next();

	String res = check(s);
	System.out.println(res);
}

}

pls help me what is the problem in my code.

@nigamshubham1998 hi buddy reviewing it!

@nigamshubham1998 buddy see if the input is:-
aaccb
expected :- a2c2b
your:- a2bc2
So ordering is not preserved.
So handle that case.
If your doubt is resolved mark it resolved and rate full else ask if any query bro, and handle this edge case you will be good to go!