Step 1: Initialize left=0, right=1 to start comparing
[1, 1, 2, 3, 3, 4, 5]
↑ ↑
left right
Why: We need two pointers to compare adjacent elements
Step 2: Compare array[left]=1 and array[right]=1, they are equal, move right forward
[1, 1, 2, 3, 3, 4, 5]
↑ ↑
left right
Why: Skip duplicate by moving right pointer
Step 3: Compare array[left]=1 and array[right]=2, different values found
[1, 1, 2, 3, 3, 4, 5]
↑ ↑
left right
Why: Found a new unique element
Step 4: Increment left to 1 and copy array[right]=2 to array[left]
[1, 2, 2, 3, 3, 4, 5]
↑ ↑
left rightWhy: Overwrite duplicate position with new unique element
Step 5: Move right to 3, compare array[left]=2 and array[right]=3, different
[1, 2, 2, 3, 3, 4, 5]
↑ ↑
left rightWhy: Next unique element found
Step 6: Increment left to 2 and copy array[right]=3 to array[left]
[1, 2, 3, 3, 3, 4, 5]
↑ ↑
left rightWhy: Place unique element next in line
Step 7: Move right to 4, compare array[left]=3 and array[right]=3, equal, move right forward
[1, 2, 3, 3, 3, 4, 5]
↑ ↑
left rightStep 8: Compare array[left]=3 and array[right]=4, different
[1, 2, 3, 3, 3, 4, 5]
↑ ↑
left rightWhy: New unique element found
Step 9: Increment left to 3 and copy array[right]=4 to array[left]
[1, 2, 3, 4, 3, 4, 5]
↑ ↑
left rightWhy: Overwrite duplicate with unique element
Step 10: Move right to 6, compare array[left]=4 and array[right]=5, different
[1, 2, 3, 4, 3, 4, 5]
↑ ↑
left rightWhy: Next unique element found
Step 11: Increment left to 4 and copy array[right]=5 to array[left]
[1, 2, 3, 4, 5, 4, 5]
↑ ↑
left rightWhy: Place unique element next in line
Step 12: Right pointer reached end, stop
[1, 2, 3, 4, 5, 4, 5]
↑
leftWhy: All unique elements moved to front
Result: [1, 2, 3, 4, 5, 4, 5]
Unique elements count = 5