I know the best answer has been found. Just want to explain the problem requirement more clearly, for someone's reference in future.
This problem is described in a somewhat ambiguous way.
According to the test case, this problem asks us to move all distinct elements (suppose n totally) to the first n entries of the original array and return the value n.
I guess the Judge will then truncate and test the first n entries from original array A[].