Delete Node in Doubly Linked List
Doubly Linked List: Fundamentals DSA practice problem on Onlearn.
Difficulty: medium.
Topics: How to Delete the Tail Node from a Doubly Linked List, Doubly Linked List, Node, Pointer, Time Complexity, Space Complexity, Loops, general programming, linked list traversal, edge cases, linked list, Node, Linked List Operations.
Problem: Delete the Tail of a Doubly Linked List Problem Statement Given the head of a Doubly Linked List, your task is to delete the last node of the list. After deletion, the second to last node of the original list should become the new tail. Input Specification The input consists of a single parameter: head: A pointer/reference to the head node of the Doubly Linked List. If the list is empty, head will be null. Output Specification Return the head of the modified Doubly Linked List. If the list becomes empty after deletion, return null. Constraints The number of nodes in the linked list N can range from 0 to 10^5. Node values will be integers within the range [ 10^9, 10^9]. Example Test Cases Example 1 Input: DLL: 1 < 3 < 4 < 1 Output: DLL: 1 < 3 < 4 Explanation: The original list has 1 as its tail. After deleting 1, the node 4 becomes the new tail. The connections are updated such that 4's next pointer is null and the deleted 1's back pointer is null. Example 2 Input: DLL: 7 < 5 Output: DLL: 7 Explanation: The original list has 5 as its tail. After deleting 5, the node 7 becomes the new tail. The 7's next pointer is updated to null. Example 3 Input: DLL: 10 Output: DLL: null Explanation: If the list contains only one node, that node is the tail. Deleting it results in an empty list.