-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard_Removal.java
More file actions
37 lines (36 loc) · 1.13 KB
/
Card_Removal.java
File metadata and controls
37 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.util.Scanner;
public class Card_Removal {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
int[] arr = new int[n];
for(int i = 0;i<n;i++){
arr[i] = sc.nextInt();
}
//array assign for zero
int[] numberRepeat = new int[n];
for(int i = 0; i<n;i++){
numberRepeat[i]=0;
}
//corresponding with number of occurences
for(int i=0;i<n;i++){
int element = arr[i];
for(int j = 0;j<n;j++){
if(element == arr[j]){
numberRepeat[i]++;
}
}
}
//finding the max number of occurrences
int maxRepeat = numberRepeat[0];
for(int i = 0; i<n; i++){
if(maxRepeat<numberRepeat[i]){
maxRepeat = numberRepeat[i];
}
}
System.out.println(n- maxRepeat);
}
}
}