How do you delete a node given only its pointer in a singly linked list?

DSA
Medium
Microsoft
71.7K views

Direct Answer

This is a classic data structure problem testing logical manipulation of pointers. It checks if you understand memory management and list traversal constraints.

Why Interviewers Ask This

This question evaluates your fundamental grasp of linked list mechanics and edge case handling. Interviewers look for your ability to realize that you cannot access the previous node to update its next pointer. It tests creativity in solving problems within strict constraints and your understanding of time complexity trade-offs.

How to Answer This Question

Immediately clarify that you cannot delete the tail node directly without a reference to the previous one. Explain the standard trick: copy the value of the next node into the current node, then bypass the next node by updating the current node's next pointer. Mention the exception case where the node to be deleted is the tail. Keep the explanation concise and focus on the O(1) time complexity aspect.

Key Points to Cover

  • Copy next node value to current
  • Update next pointer to skip node
  • Handling the tail node exception
  • O(1) time complexity for non-tail

Sample Answer

Since we only have a pointer to the node to be deleted and not the head, we cannot traverse backwards to update the previous node's link. The standard approach is to copy the data from the next node into the current node…

Common Mistakes to Avoid

  • Attempting to free memory without updating links
  • Forgetting to handle the tail node case
  • Confusing doubly linked list logic

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 127 DSA questionsBrowse all 107 Microsoft questions