Help me in solving REMOVECARDS problem

What is wrong with my approach?
Code is failed in some test cases

/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		int larger;
		while(t-->0){
		    int n=sc.nextInt();
		    int A[]=new int[n];
		    int N[]={0,0,0,0,0,0,0,0,0,0};
		    for(int i=0;i<n;i++){
		        A[i]=sc.nextInt();
		    }
		    for(int i=0;i<n;i++){
		        N[A[i]-1]++;
		    }
		    larger=N[0];
		    for(int i=0;i<8;i++){
		        if(N[i]<N[i+1]){
		            larger=N[i+1];
		        }
		    }
		    System.out.println(n-larger);
		}
	}
}

@sushiljaishi
Have corrected your code .
Just a little correction in calculating larger.

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

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
		int t=sc.nextInt();
		int larger;
		while(t-->0){
		    int n=sc.nextInt();
		    int A[]=new int[n];
		    int N[]={0,0,0,0,0,0,0,0,0,0};
		    for(int i=0;i<n;i++){
		        A[i]=sc.nextInt();
		    }
		    for(int i=0;i<n;i++){
		        N[A[i]-1]++;
		    }
		    larger=N[0];
		    for(int i=1;i<10;i++){
		        if(N[i]>larger){
		            larger=N[i];
		        }
		    }
		    System.out.println(n-larger);
		}
	}
}
1 Like