Bird
Raised Fist0
DSA Typescriptprogramming~20 mins

Delete from End of Doubly Linked List in DSA Typescript - Practice Problems & Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Doubly Linked List Deletion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output after deleting last node from doubly linked list
What is the printed state of the doubly linked list after deleting the last node?
DSA Typescript
class Node {
  data: number;
  next: Node | null;
  prev: Node | null;
  constructor(data: number) {
    this.data = data;
    this.next = null;
    this.prev = null;
  }
}

class DoublyLinkedList {
  head: Node | null = null;

  append(data: number) {
    const newNode = new Node(data);
    if (!this.head) {
      this.head = newNode;
      return;
    }
    let temp = this.head;
    while (temp.next) {
      temp = temp.next;
    }
    temp.next = newNode;
    newNode.prev = temp;
  }

  deleteFromEnd() {
    if (!this.head) return;
    if (!this.head.next) {
      this.head = null;
      return;
    }
    let temp = this.head;
    while (temp.next) {
      temp = temp.next;
    }
    temp.prev!.next = null;
  }

  printList() {
    let temp = this.head;
    let result = '';
    while (temp) {
      result += temp.data + ' -> ';
      temp = temp.next;
    }
    result += 'null';
    console.log(result);
  }
}

const dll = new DoublyLinkedList();
dll.append(10);
dll.append(20);
dll.append(30);
dll.deleteFromEnd();
dll.printList();
Anull
B10 -> 20 -> 30 -> null
C20 -> 30 -> null
D10 -> 20 -> null
Attempts:
2 left
💡 Hint
Think about what happens to the last node and its previous node when deleting from the end.
❓ Predict Output
intermediate
2:00remaining
Output after deleting last node from single-node doubly linked list
What is the printed state of the doubly linked list after deleting the last node when the list has only one node?
DSA Typescript
class Node {
  data: number;
  next: Node | null;
  prev: Node | null;
  constructor(data: number) {
    this.data = data;
    this.next = null;
    this.prev = null;
  }
}

class DoublyLinkedList {
  head: Node | null = null;

  append(data: number) {
    const newNode = new Node(data);
    if (!this.head) {
      this.head = newNode;
      return;
    }
    let temp = this.head;
    while (temp.next) {
      temp = temp.next;
    }
    temp.next = newNode;
    newNode.prev = temp;
  }

  deleteFromEnd() {
    if (!this.head) return;
    if (!this.head.next) {
      this.head = null;
      return;
    }
    let temp = this.head;
    while (temp.next) {
      temp = temp.next;
    }
    temp.prev!.next = null;
  }

  printList() {
    let temp = this.head;
    let result = '';
    while (temp) {
      result += temp.data + ' -> ';
      temp = temp.next;
    }
    result += 'null';
    console.log(result);
  }
}

const dll = new DoublyLinkedList();
dll.append(100);
dll.deleteFromEnd();
dll.printList();
A100 -> null
Bnull
CError: Cannot read property 'next' of null
D100 -> 100 -> null
Attempts:
2 left
💡 Hint
Deleting the last node when only one node exists should empty the list.
🔧 Debug
advanced
2:00remaining
Identify the error in deleteFromEnd method
What error will this code produce when deleting from an empty doubly linked list?
DSA Typescript
class Node {
  data: number;
  next: Node | null;
  prev: Node | null;
  constructor(data: number) {
    this.data = data;
    this.next = null;
    this.prev = null;
  }
}

class DoublyLinkedList {
  head: Node | null = null;

  deleteFromEnd() {
    let temp = this.head!;
    while (temp.next) {
      temp = temp.next;
    }
    temp.prev!.next = null;
  }
}

const dll = new DoublyLinkedList();
dll.deleteFromEnd();
ATypeError: Cannot read property 'next' of null
BReferenceError: temp is not defined
CNo error, runs successfully
DSyntaxError: Unexpected token '!'
Attempts:
2 left
💡 Hint
Consider what happens when head is null and you try to access its properties.
❓ Predict Output
advanced
2:00remaining
Output after multiple deletions from end
What is the printed state of the doubly linked list after deleting the last node twice?
DSA Typescript
class Node {
  data: number;
  next: Node | null;
  prev: Node | null;
  constructor(data: number) {
    this.data = data;
    this.next = null;
    this.prev = null;
  }
}

class DoublyLinkedList {
  head: Node | null = null;

  append(data: number) {
    const newNode = new Node(data);
    if (!this.head) {
      this.head = newNode;
      return;
    }
    let temp = this.head;
    while (temp.next) {
      temp = temp.next;
    }
    temp.next = newNode;
    newNode.prev = temp;
  }

  deleteFromEnd() {
    if (!this.head) return;
    if (!this.head.next) {
      this.head = null;
      return;
    }
    let temp = this.head;
    while (temp.next) {
      temp = temp.next;
    }
    temp.prev!.next = null;
  }

  printList() {
    let temp = this.head;
    let result = '';
    while (temp) {
      result += temp.data + ' -> ';
      temp = temp.next;
    }
    result += 'null';
    console.log(result);
  }
}

const dll = new DoublyLinkedList();
dll.append(5);
dll.append(15);
dll.append(25);
dll.deleteFromEnd();
dll.deleteFromEnd();
dll.printList();
A5 -> null
B5 -> 15 -> null
C15 -> 25 -> null
Dnull
Attempts:
2 left
💡 Hint
Each deleteFromEnd removes the last node. After two deletions, only the first node remains.
🧠 Conceptual
expert
2:00remaining
Why is prev pointer important in deleteFromEnd of doubly linked list?
Which statement best explains why the 'prev' pointer is used when deleting the last node in a doubly linked list?
AIt is used to traverse the list from head to tail.
BIt helps to find the head of the list quickly.
CIt allows direct access to the node before the last node to update its next pointer to null.
DIt stores the data of the last node for deletion.
Attempts:
2 left
💡 Hint
Think about how to remove the last node without traversing the entire list again.

Practice

(1/5)
1. What happens to the tail pointer when you delete the last node from a doubly linked list?
easy
A. It becomes null immediately
B. It moves to the previous node of the deleted node
C. It points to the head node
D. It remains unchanged

Solution

  1. Step 1: Understand the tail pointer role

    The tail pointer always points to the last node in the list.
  2. Step 2: Effect of deleting the last node

    When the last node is deleted, the tail must move to the previous node to remain the last node.
  3. Final Answer:

    It moves to the previous node of the deleted node -> Option B
  4. Quick Check:

    Tail updates to previous node after deletion [OK]
Hint: Tail always points to last node, so move it back after deletion [OK]
Common Mistakes:
  • Setting tail to null without checking if list is empty
  • Not updating tail pointer after deletion
  • Confusing head and tail pointers
  • Assuming tail points to head after deletion
2. Which of the following is the correct TypeScript syntax to delete the last node from a doubly linked list assuming tail is not null?
easy
A. tail = tail.prev; tail.next = null;
B. tail = tail.next; tail.prev = null;
C. tail = null; head = null;
D. tail.prev = tail; tail.next = null;

Solution

  1. Step 1: Move tail pointer to previous node

    To delete the last node, tail must point to its previous node: tail = tail.prev;
  2. Step 2: Set new tail's next to null

    Since tail is now last node, its next must be null: tail.next = null;
  3. Final Answer:

    tail = tail.prev; tail.next = null; -> Option A
  4. Quick Check:

    Correct syntax moves tail back and nullifies next [OK]
Hint: Tail moves back, then tail.next set to null [OK]
Common Mistakes:
  • Moving tail forward instead of backward
  • Not setting tail.next to null
  • Setting tail to null without updating links
  • Confusing prev and next pointers
3. Given the doubly linked list: 1 <-> 2 <-> 3 <-> 4 <-> null, what is the list after deleting the last node?
medium
A. 1 <-> 2 <-> 3 <-> null
B. 1 <-> 2 <-> 3 <-> 4 <-> null
C. 2 <-> 3 <-> 4 <-> null
D. 1 <-> 2 <-> null

Solution

  1. Step 1: Identify the last node

    The last node is 4, pointed by tail.
  2. Step 2: Delete last node and update tail

    Remove node 4, update tail to node 3, set tail.next to null.
  3. Final Answer:

    1 <-> 2 <-> 3 <-> null -> Option A
  4. Quick Check:

    Last node 4 removed, tail now 3 [OK]
Hint: Remove last node, tail moves to previous node [OK]
Common Mistakes:
  • Not updating tail pointer
  • Leaving deleted node linked
  • Removing wrong node
  • Confusing head and tail updates
4. Consider this TypeScript code snippet to delete the last node from a doubly linked list:
if (tail !== null) {
  tail = tail.prev;
  tail.next = null;
}
What error can occur here?
medium
A. No error, code is correct
B. Syntax error due to missing semicolon
C. Runtime error if list has only one node
D. Tail pointer moves forward incorrectly

Solution

  1. Step 1: Analyze single-node list case

    If list has one node, tail.prev is null, so tail becomes null.
  2. Step 2: Accessing tail.next causes error

    After tail = tail.prev (null), next line tries tail.next = null, causing runtime error (cannot access property of null).
  3. Final Answer:

    Runtime error if list has only one node -> Option C
  4. Quick Check:

    Null tail causes runtime error on next access [OK]
Hint: Check if tail.prev is null before setting tail.next [OK]
Common Mistakes:
  • Not handling single-node list edge case
  • Assuming tail is never null after update
  • Ignoring runtime null pointer errors
  • Confusing syntax errors with runtime errors
5. You have a doubly linked list with nodes: 10 <-> 20 <-> 30. After deleting the last node twice, what is the final list?
hard
A. 10 <-> 20 <-> null
B. 20 <-> null
C. null
D. 10 <-> null

Solution

  1. Step 1: Delete last node first time

    Last node 30 is removed, tail moves to 20, list becomes 10 <-> 20 <-> null.
  2. Step 2: Delete last node second time

    Last node 20 is removed, tail moves to 10, list becomes 10 <-> null.
  3. Step 3: Verify final list

    After two deletions, list is 10 <-> null.
  4. Final Answer:

    10 <-> null -> Option D
  5. Quick Check:

    Two deletions remove 30 and 20, leaving 10 [OK]
Hint: Delete last node twice removes last two nodes [OK]
Common Mistakes:
  • Deleting only one node instead of two
  • Confusing node values after deletion
  • Not updating tail pointer correctly
  • Assuming list becomes empty too early
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard