Interview Query

Pop Tail

Start Timer

0:00:00

Upvote
3
Downvote
Save question
Mark as completed
View comments (3)
Next question

You are given two ListNodes of a doubly linked list. Write a function pop_tail which removes the tail of the linked list in O(1)O(1) time. Return the head and tail of the linked list as a list. If the linked list is empty after removal, return None.

A ListNode is defined as:

class ListNode:
  value: ListNode = None
  next: ListNode = None
  prev: ListNode = None

Example:

Input:

3 -> 2 -> 4 -> 5 -> 7
head = ListNode(3)
tail = ListNode(7)

Output:

def pop_tail(head: ListNode, tail:ListNode) -> [ListNode(3), ListNode(5)]
.
.
.
.
.


Comments

Loading comments...