Hey… I’ve been stuck at this question for quite some time now… Review: ArrayList Operations – CodeChef | Competitive Programming | Participate & Learn
All sample test cases are passing but still getting wrong answer while submitting… not able to figure out which test case it is failing for
Here’s my code :
import java.util.*;
class Codechef
{
public static void main (String[] args)
{
Scanner read = new Scanner(System.in);
int t = read.nextInt();
for(int i=0; i<t; i++)
{
ArrayList a = new ArrayList();
int n = read.nextInt();
for(int j=1; j<=n; j++){
int ele = read.nextInt();
a.add(ele);
}
// Update the code below to solve this problem
for(int j=0; j<a.size()-1;){
if(j<a.size()-1 && a.get(j)==a.get(j+1) || j>0 && a.get(j)==a.get(j-1)){
a.remove(j);
}
else j++;
}
System.out.println(a.size());
}
}
}