Naive Approach (Two Passes)
Idea:
-
First pass: Count the total number of nodes in the list (
length). -
Second pass: Traverse again and stop at the
(length - n)th node (just before the one to be deleted). -
Update the
nextpointer to skip the target node.
