My code gives incorrect answer for test case 1 and 2. It also gives tle for test case 3. Please let me know my mistake.
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int[] arr = new int[26];
String str = scn.nextLine();
int len = str.length();
for(int i =0;i<len;i++){
arr[str.charAt(i)-'a']++;
}
for(int i =0;i<26;i++){
if(arr[i]>0){
int ascii = 97+i;
char ch = (char)(ascii);
System.out.print(ch);
System.out.print(arr[i]);
}
}
}
}