Workspace Read Write Pointers
0d
Problem-solving patterns

Read and Write Cursors

Read the input once while writing a valid output prefix in place.

Recognition signal

Items must be retained, removed or compacted without a new array.

Method

Keep the write position at or before the current read position.

Worked example

Compacting [2, 2, 5] writes 5 into slot 1 and returns length 2.

Common mistake

The physical tail may still hold obsolete values after logical compaction.