easyLinked ListLinked List

Remove Nth Node From End of List

easyTime: O(n)Space: O(1)

Signals to notice

remove nth node from endsingle pass preferredneed the node before the target

Brute force first

Count length, compute position from start, remove — two passes. It is a fair place to begin because it matches the surface of the question, yet it does not capture the deeper structure that makes the problem simpler.

The key insight

Two pointers n apart: when fast reaches end, slow is at the node before the target — single pass. Instead of recomputing the world every time, you preserve just enough context to let the next decision become obvious.

What must stay true

If fast is n nodes ahead of slow, when fast reaches the end, slow is at position length - n. As long as that statement keeps holding, you can trust the steps built on top of it.

Easy way to go wrong

Forgetting the dummy head — needed when removing the actual head node. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.

Linked List Pattern