# Delete the Middle Node of a Linked List

Category

Linked List

Checkbox

Checkbox

Difficulty

Medium

Index

29

Key Ideas

The key idea to solve the problem "Delete the Middle Node of a Linked List" is to use the two-pointer technique to find the middle node and modify the links to remove it.

Problem Number

2095

Problem Summary

**Problem Summary:**The problem "Delete the Middle Node of a Linked List" requires deleting the middle node of a singly linked list, given only access to that node. The goal is to modify the linked list in-place and maintain its original structure.

**Key Pitfalls:**One key pitfall is that the given node will not be the first or last node of the linked list. Another pitfall is that the problem does not provide access to the head of the linked list, so the solution must be implemented without knowing the overall size of the list or being able to traverse it from the beginning.

Solution Summary

The best solution to delete the middle node of a linked list is to use the Two Pointers technique. We can have two pointers, a slow pointer and a fast pointer, initially pointing to the head of the linked list. The fast pointer moves twice as fast as the slow pointer. As the fast pointer reaches the end of the linked list, the slow pointer will be at the middle node. To delete the middle node, we simply update the next pointer of the node before the slow pointer to point to the node after the slow pointer. This effectively removes the middle node from the linked list. The time complexity of this solution is O(n), where n is the length of the linked list.

Tags

Linked List

Two Pointers