Help me in solving AOJ09 problem

My issue

what is wrong in my code

My code

import java.util.*;
class Codechef
{
	public static void main (String[] args)
	{
		Scanner read = new Scanner(System.in);
		int t = read.nextInt();
		int ele;
		for(int i=0; i<t; i++)
		{
    		int n = read.nextInt();
    		// Declare an array of size 'n'
    		int[] a = new int[n];
    		for(int j=0; j<n; j++){
    		    a[j] = read.nextInt(); 
    		}
    		// sorting the array because we want to find most frequent element
    		Arrays.sort(a);
    		
    		// Update the code below to solve the problem
    		ArrayList<Integer> b=new ArrayList<Integer>();
    		for(int j=0;j<n;j++){
    		    b.add(Collections.frequency(a,a.get(j)));
    		}
    		m=b.size();
    		System.out.println(Math.abs(n-m));

    		
		}
	}
}

Learning course: Solve Programming problems using Java
Problem Link: Practice problem - Make all equal using Pairs Practice Problem in Solve Programming problems using Java - CodeChef

@dineshvt_4220
plzz refer the following code for better understanding

import java.util.*;
class Codechef
{
	public static void main (String[] args)
	{
		Scanner read = new Scanner(System.in);
		int t = read.nextInt();
		int ele;
		for(int i=0; i<t; i++)
		{
    		int n = read.nextInt();
    		// Declare an array of size 'n'
    		int[] a = new int[n];
    		for(int j=0; j<n; j++){
    		    a[j] = read.nextInt(); 
    		}
    		// sorting the array because we want to find most frequent element
    		Arrays.sort(a);
    		int mx=1;
    		int cnt=1;
    		for(int j=1;j<n;j++)
    		{
    		    if(a[j]==a[j-1])
    		    cnt++;
    		    else{
    		        cnt=1;
    		    }
    		     if(mx<cnt)
    		        mx=cnt;
    		}
    		System.out.println(n-mx);
    		// Update the code below to solve the problem
		}
	}
}