if (arr[i] != arr [i + 1] temp [j++] = arr[i] temp [j++] = arr[n- 1] Repeat from i = 1 to j arr[i] = temp[i] arr [i] = temp [i] Return j.