i and j to 1 and 0 respectively.count to 1 to keep track of the count of each unique element.count.count is less than or equal to 2, copy the current element to the position at j and increment j.count to 1 and copy the element to the position at j and increment j.j as the new length of the array.