Can you please tell me what is wrong with my code? it is only passing one test case.
import java.util.*;
public class Main {
public static void countSort(int []arr,int n,int max)
{
int []count=new int[max+1];
for(int i=0;i<n;i++)
{
count[arr[i]]++;
}
for(int i=1;i<=max;i++)
{
count[i]+=count[i-1];
}
int []output =new int[n+1];
for(int i= n-1;i>=0;i--)
{
output[count[arr[i]]-1]=arr[i];
count[arr[i]]--;
}
for(int i=0;i<n;i++)
{
arr[i]=output[i];
}
for(int i=0;i<n;i++)
{
System.out.print(arr[i]+" ");
}
}
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int []arr=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
int max=Integer.MIN_VALUE;
for(int i=0;i<n;i++)
{
if(arr[i]>max)
{
max=arr[i];
}
}
countSort(arr,n,max);
}
}