Skip to content

Delete Middle Node

EasyPython 3Linked lists

Implement an algorithm to delete a node from the middle of a singly linked list, given access ONLY to that node (you do not have the head of the list). After the call, the target node's value must be gone from the list and every other value must remain in its original order.

Constraints:
  - The given node is not None.
  - The given node is not the tail (last) node of the list; the tail cannot be
    deleted with only a reference to it.
  - Node values are integers.
Examples:
  1 -> 2 -> [3] -> 4 -> 5,  delete node holding 3   =>  1 -> 2 -> 4 -> 5
  [1] -> 2 -> 3,            delete node holding 1   =>  2 -> 3
  1 -> 2 -> 3 -> [4] -> 5,  delete node holding 4   =>  1 -> 2 -> 3 -> 5

Python 3, run in your browser. Run tests runs the problem's own tests with a free account; the AI interviewer reads your code and your runs in a practice interview.

Loading the editor…