Im getting WA on subtask 2 even though i checked all cases according to me it would be great if someone points out the error in my code…will help a lot thanks
My code-CodeChef: Practical coding for everyone
My solution is also similar to yours and I am also getting the WA in subtask 2.
/* 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 scan=new Scanner(System.in);
int test=scan.nextInt();
while(test-->0)
{
int n=scan.nextInt();
int k=scan.nextInt();
int max=0;
int steps=0;
int count=0;
int array[]=new int[n];
HashMap<Integer,Integer> map=new HashMap<>();
for(int i=0;i<n;i++){
array[i]=scan.nextInt();
}
for(int i=0;i<n;i++){
if(count<=k-1){
if(!map.containsKey(array[i])){
map.put(array[i],1);
count++;
}
if(count<=k-1){
steps++;
}
else{
steps=1;
count=1;
map=new HashMap<Integer,Integer>();
map.put(array[i],1);
}
if(max<steps){
max=steps;
}
}
}
System.out.println(max);
}
}
}