How do you delete a node given only a pointer to it in a linked list?

Coding
Easy
Goldman Sachs
66.8K views

This unique problem tests your understanding of memory manipulation and pointer arithmetic in linked lists without access to the head.

Why Interviewers Ask This

Interviewers use this to see if candidates understand the limitations of singly linked lists. It tests creative problem-solving when standard deletion methods (accessing previous node) are unavailable. It also checks attention to detail regarding the last node scenario.

How to Answer This Question

Explain why standard deletion fails without the previous pointer. Propose the copy-and-delete strategy: copy next node's data to current, then bypass the next node. Explicitly mention that this cannot be done for the tail node. Discuss the implications of this modification on the list structure.

Key Points to Cover

  • Copy next node's data
  • Update next pointer
  • Cannot delete tail node directly
  • O(1) time complexity

Sample Answer

Since I cannot access the previous node, I will copy the value of the next node into the current node. Then, I will update the current node's next pointer to skip the next node, effectively deleting it. This works for al…

Common Mistakes to Avoid

  • Attempting to access previous node
  • Failing to handle the tail node exception
  • Confusing singly and doubly linked list operations

Sound confident on this question in 5 minutes

Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.

Try it free

Related Interview Questions

Browse all 80 Coding questionsBrowse all 29 Goldman Sachs questions