Help me in solving REDUARRAY problem

My issue

someone can help in type casting what’s wrong int this

My code

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

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
        Scanner sc = new Scanner(System.in);

        int T = sc.nextInt(); // Number of test cases

        while (T-- > 0) {
            int n = sc.nextInt(); 
             HashMap<Integer,Integer>map=new HashMap<Integer,Integer>();
            for(int i=0;i<n;i++){
                int x=sc.nextInt();
               map.put(x,map.getOrDefault(x,0)+1);
            }
            
            long y=(long)Integer.MAX_VALUE;
           
           for(Integer x:map.keySet()){
             y=Math.min(y,((long)(n-map.get(x)))*((long)x));  
           }
           
           
        System.out.println(y);
           
        }
	}
}

Problem Link: Redundant Array Practice Coding Problem

@deepakjdh31
here plzz refer my c++ code for better understanding of logic

#include <bits/stdc++.h>
//#define  long long int int
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    map<long long int,long long int> mp;
	    long long int n;
	    cin>>n;
	    long long int a[n];
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	        mp[a[i]]++;
	    }
	    long long int ans=n;
	    for(auto x:mp)
	    {
	        long long int val=n-x.second;
	        long long int ch=val*x.first;
	        ans=min(ans,ch);
	    }
	    cout<<ans<<endl;
	}
	return 0;
}