HASHMAP(geeks for geeks problem)

My problem statement is from geeksforgeeks website :
Question Link: https://practice.geeksforgeeks.org/problems/sherlock-a-detective/0
Solution:
My approach to solution is that i am creating a hashmap with all the values till array length and putting the corresponding value to 0, now i will check with the array values that if a key and array value is same then we will change the value of that corresponding key and hence according to the question the unreported people value will be 0.while printing there is some error,Please Help!!

/*package whatever //do not write package name here */

import java.util.;
import java.lang.
;
import java.io.*;
import java.util.Iterator;
import java.util.Set;
class GFG {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int k=0;k<t;k++)
{
int n=sc.nextInt();
int a[]=new int[n];
HashMap<Integer,Integer> map=new HashMap<>();
for(int j=0;j<n;j++)
{
a[j]=sc.nextInt();
map.put(j,0);

        }
        map.put(n,0);
        for(int i=0;i<n;i++)
        {
            if(map.containsKey(a[i]))
            {
                int ov=map.get(a[i]);
                int nv=ov+1;
                map.put(a[i],nv);
            }
        }
     Set<Map.Entry<Integer,Integer>> entries=map.entrySet();
        int max=0;
        for(Map.Entry<Integer,Integer> entry :entries)
        {
            if(entry.getValue()==0)
            {
             max=entry.getKey();         
             System.out.print(max+ " ");
           
           }
                
        }
     
        
    }
}

}