Delete the given node (except tail) from a singly linked list.
Approach
Copy the next node’s value and pointer.
Time O(1)Space O(1)
How it works
1Copy the next node's value into the target.
2Bypass the next node.
3Works because the node is never the tail.
Sample input / output
Input:
4
4 5 1 9
1
Output:
[4, 1, 9]
Constraints
2 <= nodes <= 1000; node to delete is not the tail.
Solution — read it, then walk it
Time O(1)Space O(1)Loops 3Branches 1Returns 2source · Python
Scroll sideways for wide charts — the view follows the active step.
start / end
statement
condition
loop
returns
definition
1/35
StartSTART
Interactive control-flow diagram and step-by-step code walkthrough.
Recommended resourcesAffiliate links · may earn us a commission
Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books →Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses →Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits →