Delete a Node in a Doubly Linked List
Implement deleteDLL
Given the head of a doubly linked list and a 0-indexed position, delete the node at that position and return the new head. Position 0 means deleting the head itself.
Removing a node from the middle only ever touches the pointers of its immediate neighbors — nothing else in the list changes. In a singly linked list, that means redirecting one next pointer to skip past the removed node; in a doubly linked list, the node right after it also has its prev pointer redirected back to the one before, so the shortened list still reads correctly in both directions.
Example 1:
Input: head = [2,5,6,7,9], position = 2
Output: [2,5,7,9]
Example 2:
Input: head = [1,2,3], position = 0
Output: [2,3]
Example 3:
Input: head = [5], position = 0
Output: []
+ 4 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ number of nodes in head ≤ 200 - ●
-1000 ≤ node value ≤ 1000 - ●
0 ≤ position < length of head — position is 0-indexed - ●
This platform's judge reads back only the forward (next) traversal — a real doubly linked implementation also relinks the removed node's neighbors' .prev pointers
head =
[2, 5, 6, 7, 9]
position =
2