Codechef uncle johny problem(error)

Scanner s=new Scanner(System.in);
int T=s.nextInt();
while(T–> 0)
{
int n=s.nextInt();
int[] a=new int[n];
for(int i=0;i < n;i++)
{
a[i]=s.nextInt();
}
int k=s.nextInt();

           HashMap<Integer,Integer> map=new HashMap<>();
           for(int i=0;i < n;i++)
           {
               map.put(i,a[i]);
           }
           Arrays.sort(a);
           int val=0;
           if(map.containsKey(k))
           {
               val = map.get(k);
           }
           int count=0;
           while(a[count] != val)
           {
               count++;
           }
           System.out.println(count);
           
       }


}