Not able to understand why time limit exceed for few cases

    int i =0;
    int j =a.size();
    while(i<a.size()-1){
        if(a.get(i).equals( a.get(i+1)) ){
            a.remove(i);
            j--;
        } else {
            i++;
        }
    }
    return j;

In any language using list.remove() is not constant time. It is linear. Your algorithm itself is O(N^2).

Click here to start solving coding interview questions