</>EmbeddedInterview

Delete a node when you are given only a pointer to that node (no head).

Medium"Coding: Linked Lists, Stacks & Queues"
/* copies the next node into this one and frees the next node */
int delete_given_node(node_t *n)
{
    if (n == NULL || n->next == NULL) return -1;  /* cannot delete the last node this way */
    node_t *next = n->next;
    n->val = next->val;
    n->next = next->next;
    free(next);
    return 0;
}

Points: you cannot find the previous node, so copy the successor's data into this node and remove the successor instead. It does not work for the tail, and it breaks if other code holds pointers to the successor node (its identity changes), which is why it is a trick, not a general technique.