Delete a node from a singly-linked list in O(1) time and O(1) space
getrevue.co
getrevue.co
From the ‘solution’:
// if the next node is nil, it's the last node.
// this implementation does not work.
On top of that, the ‘solution’ doesn’t delete the node given; it deletes the one after it, but copies its value to the node to be deleted. That may be fine in some cases, but problematic in others, say when other code uses node addresses to access nodes.I would change the problem statement to ”_Remove_ a _value_ from a _circular_ singly-linked list, given only a pointer to the node containing the value.”