Help me in solving REDUARRAY problem

My issue

givve solution

My code

import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
	    Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		while(t-->0)
		{
		   
		    int n=sc.nextInt();
		    int a[]=new int[n];
		    for(int i=0;i<n;i++)
		    a[i]=sc.nextInt();
		    
		   System.out.println(minoperation(a,n));
		}

	}
	public static int minoperation(int a[],int n)
	{
	    int ans=Integer.MAX_VALUE;
	    HashMap<Integer,Integer>hm=new HashMap<>();
	    for(int i=0;i<n;i++)
	    {
	        if(hm.containsKey(a[i]))
	         hm.put(a[i],hm.get(a[i])+1);
	        else
	          hm.put(a[i],1);
	       
	    }
	 for (Integer key : hm.keySet()) {
            ans=Math.min(ans,(n-hm.get(key))*key);
        }
        if(ans>n)
	    return n;
	    
	    
	    return ans;
	}
}

Problem Link: Redundant Array Practice Coding Problem

ans can be greater than INT_MAX length
Take long long for storing ans