Giving Wrong Output for testcases


#1
public class Solution {
    public int removeDuplicates(ArrayList<Integer> A) {
        int i=2;
        while(i<A.size()){
            if(A.get(i)==A.get(i-2)) A.remove(i);
            else i++;
        }
        return A.size();
    }
}

i/p- 10 1000 1000 1000 1000 1001 1002 1003 1003 1004 1010
o/p- [1000 1000 1000 1000 1001 1002 1003 1003 1004 1010]

the statement if(A.get(i)==A.get(i-2)) is unable to check condition properly. Please someone help


#2
  1. Check complexity of remove function.
  2. Equality check using equals - A.get(i).equals(A.get(i+2))) , == will check for the memory address and not the value itself.