Step 1: Initialize left at index 0, right at index 1
[1, 1, 2, 3, 3, 4, 5]
↑left ↑right
Why: Start comparing from the first two elements to find duplicates
Step 2: Compare values at left and right; both are 1, duplicate found, move right forward
[1, 1, 2, 3, 3, 4, 5]
↑left ↑right
Why: Skip duplicate by moving right pointer to find next unique value
Step 3: Values differ (1 and 2), move left forward and overwrite left with right value (2)
[1, 2, 2, 3, 3, 4, 5]
↑left ↑rightWhy: Place unique value next to last unique and advance left pointer
Step 4: Move right forward to index 3, compare values at left (2) and right (3), different
[1, 2, 2, 3, 3, 4, 5]
↑left ↑rightWhy: Found next unique value, prepare to overwrite
Step 5: Move left forward and overwrite left with right value (3)
[1, 2, 3, 3, 3, 4, 5]
↑left ↑rightWhy: Keep unique values compacted at front
Step 6: Move right forward to index 4, values at left (3) and right (3) are same, duplicate found, move right forward
[1, 2, 3, 3, 3, 4, 5]
↑left ↑rightWhy: Skip duplicate by advancing right pointer
Step 7: Values at left (3) and right (4) differ, move left forward and overwrite left with right value (4)
[1, 2, 3, 4, 3, 4, 5]
↑left ↑rightWhy: Add next unique value to compacted front
Step 8: Move right forward to index 6, values at left (4) and right (5) differ, move left forward and overwrite left with right value (5)
[1, 2, 3, 4, 5, 4, 5]
↑left ↑rightWhy: Add last unique value
Result: [1, 2, 3, 4, 5, 4, 5]
Unique count = 5