892. Delete Tail of Doubly Linked List

Given the head of a doubly linked list, remove the node at the tail of the linked list and return the head of the modified list.

The tail is the last node of the linked list.

Example 1:

Input: head = [1, 2, 3]

Output: head = [1, 2]

Explanation:

  • The node with value 3 was removed.

Example 2:

Input: head = [7]

Output: head = [ ]

Explanation:

  • Note that the head has null value after the removal.

Now Your Turn!

Pick the correct output for the given input

Input: head = [2, 4]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • n == Number of nodes in the linked list
  • 1 <= n <= 100
  • 0 <= ListNode.val <= 100

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
/**
class ListNode
{
* Definition for doubly-linked list.
* public:
* int data;
* ListNode *prev;
* ListNode *next;
* ListNode() : data(0), prev(nullptr), next(nullptr) {}
* ListNode(int x) : data(x), prev(nullptr), next(nullptr) {}
* ListNode(int x, ListNode *prev, ListNode *next) : data(x), prev(prev), next(next) {}
};
*/
 
class Solution {
public:
ListNode *deleteTail(ListNode *&head) {
// Your code goes here
}
};
Test Case

Input:

Nums