Delete a Given Linked-list Node
Problem statement
You are given a reference node to a non-tail node in a singly linked list, with no reference to the list head or predecessor. Delete the logical element at that position without traversing the list. Preserve the given node object so aliases to it observe the modified contents. Do not allocate a replacement list.
For this exercise, values may be copied: copy the successor value into the given node and bypass the successor node. Return the same modified node reference so the runner can display the remaining chain. The serialized input and output show only the suffix reachable from this node; any earlier prefix is outside the interface. Node identity beyond retaining this reference is not the deleted logical value.
A tail node cannot be handled under this interface, so a successor is guaranteed. The automated runner compares the returned chain values; alias mutation and no-traversal are explicit implementation requirements.
Function
deleteGivenNode(node: ListNode) → ListNodeExamples
Example 1
node = [4,5,1,9]return = [5,1,9]Copy the successor value5 into the given node and bypass that successor. The sequence reachable from the same node becomes5,1,9.
Example 2
node = [1,2]return = [2]The successor is the tail. Copy2 and make the given node the new tail.
Example 3
node = [7,7,8]return = [7,8]Equal adjacent values do not prevent deletion: one of the two7 occurrences disappears.
Constraints
2 <= reachable node count <= 1000.-1000000 <= node value <= 1000000.The input is a finite acyclic singly linked chain.