Remove Nth From End
Lead one pointer n ahead, then walk both until the leader runs out. Trail is just before the target.
Fast and Slow Pointers: Remove the 2nd from the end
Both move. Lead at 4, trail at 2.
Cost
- Best
- O(n)
- Average
- O(n)
- Worst
- O(n)
- Space
- O(1)
Before this
Taught by the same lesson
Fast and Slow Pointers covers these too, in the same run.