My issue
where i get video solution
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 n=sc.nextInt();
for(int i=0;i<n;i++){
int l=sc.nextInt();
int target=sc.nextInt();
int [] a=new int[l];
int count=0;
int countp=0;
int counts=0;
for(int j=0;j<l;j++){
a[j]=sc.nextInt();
if(a[j]==target){
count++;
}else if(a[j]!=target && count==0){
countp++;
}
else if(a[j]!=target && count!=0){
counts++;
}
}
if(count>=l/2){
System.out.println(0);
}else if(Math.abs(l-countp)<=l/2){
System.out.println(1);
}else if(Math.abs(l-counts)<=l/2){
System.out.println(1);
}else{
System.out.println(2);
}
}
}
}
Problem Link: Make K Most Frequent Practice Coding Problem