I knew the two-pointer trick going in, but I fumbled explaining the invariant out loud.
Use a two-pointer technique with a dummy node to handle edge cases. Advance the fast pointer n+1 steps ahead, then move both pointers until fast reaches the end. The slow pointer will be just before the node to remove, allowing you to delete it in one pass.
Pro tip: Always use a dummy node pointing to the head to simplify removal of the head node and avoid separate edge case handling. Also, clarify with the interviewer whether n is guaranteed to be valid, and discuss time/space complexity upfront.
Ask if n is always valid (1 ≤ n ≤ length) and if the list can be empty. Mention edge cases like removing the head or the only node.
Create a dummy node pointing to head. Initialize two pointers (slow and fast) to the dummy node.
Move the fast pointer n+1 steps forward. This creates a gap of n nodes between slow and fast.
Move both slow and fast pointers one step at a time until fast reaches null. Now slow is just before the node to remove.
Update slow.next to skip the target node. Return dummy.next as the new head.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.