Showing TLE don`t know why?

interview-questions
Tags: #<Tag:0x00007f24256a27c8>

#1

int count=1;
for(int i=1;i<a.size();i++)
{
if(a.get(i).equals(a.get(i-1)))
{
count++;
if(count>2)
{
a.remove(i);
i–;
}
}
else
count=1;
}
return a.size();


#2

basically if you have 1 1 1, you’re removing the first 1, which will take more time than removing the last 1. That’s why it’s better to go from the end to the beginning here.


#3

bec you are trying to remove the element , read the question carefully,