Help me in redundant Array Question REDUARRAY problem

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

class Codechef
{
    static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader( 
                new InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { return Integer.parseInt(next()); } 
  
        long nextLong() { return Long.parseLong(next()); } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try { 
                if(st.hasMoreTokens()){ 
                    str = st.nextToken("\n"); 
                } 
                else{ 
                    str = br.readLine(); 
                } 
            } 
            catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
    
	public static void main (String[] args) throws java.lang.Exception
	{
		FastReader input = new FastReader();
		
		int T = input.nextInt();
		
		while(T-- > 0){
		    int len = input.nextInt();
		    int[] arr = new int[len];
		    int[] freq = new int[len];
		    
		    for(int i = 0; i < len; i++){
		        arr[i] = input.nextInt();
		        freq[arr[i]-1]++;
		    }
		    
		    int min = Integer.MAX_VALUE;
		    
		    for(int i = 1; i <= len; i++){
		        int cost = (i)*(len-freq[i-1]);
		        min = (int)Math.min(cost, min);
		    }
		    
		    System.out.println(min);
		}
	}
}

The above is my code, this works in C++ but not in Java, why is it giving me wrong answer?

your code should not run on c++
the problem is you are taking min as INT_MAX but you should take it as n
as we can take x=1 and cost for total changing array into 1 is n

but it changes to whatever is minimum, so it should not be an issue. Also i tried changing min to n, still i got error.

            long cost = (long)arr[i] * (len - freq[arr[i]]);

Changing to this line fixed the error