What does 'Delete Node at End' mean in a linked list?
It means removing the last node from a linked list, so the second last node becomes the new end.
Click to reveal answer
beginner
In a singly linked list, why do we need to traverse the list to delete the last node?
Because we only have a reference to the head and each node points forward, we must reach the second last node to update its next pointer to null.
Click to reveal answer
beginner
What happens if you delete the last node in a linked list with only one node?
The list becomes empty, so the head pointer is set to null.
Click to reveal answer
intermediate
What is the time complexity of deleting the last node in a singly linked list?
O(n), because you need to traverse the list to find the second last node.
Click to reveal answer
beginner
How do you update the linked list after deleting the last node?
Set the next pointer of the second last node to null, making it the new last node.
Click to reveal answer
What pointer do you update when deleting the last node in a singly linked list?
AThe next pointer of the last node
BThe head pointer
CThe next pointer of the second last node
DThe previous pointer of the last node
✗ Incorrect
You update the next pointer of the second last node to null to remove the last node.
What is the new last node after deleting the last node?
AThe node before the last node
BThe head node
CThe node after the last node
DThe deleted node
✗ Incorrect
The node before the last node becomes the new last node.
If a linked list has only one node, what happens after deleting the last node?
AThe list becomes empty
BThe head points to itself
CThe list remains unchanged
DThe node is duplicated
✗ Incorrect
Deleting the only node makes the list empty, so head is set to null.
What is the time complexity to delete the last node in a singly linked list?
AO(n^2)
BO(1)
CO(log n)
DO(n)
✗ Incorrect
You must traverse the list to find the second last node, so it takes O(n) time.
Which of these is NOT needed to delete the last node in a singly linked list?
AReference to the second last node
BReference to the previous node of the second last node
CReference to the last node
DReference to the head node
✗ Incorrect
You only need the head and second last node references; previous of second last is not needed.
Explain step-by-step how to delete the last node in a singly linked list.
Think about how you find the node before the last and what to do with its pointer.
You got /4 concepts.
What changes in the linked list structure after deleting the last node?
Focus on pointers and list size.
You got /4 concepts.
Practice
(1/5)
1. What does the operation Delete Node at End do in a singly linked list?
easy
A. Adds a new node at the beginning of the list
B. Removes the first node from the list
C. Removes the last node from the list
D. Adds a new node at the end of the list
Solution
Step 1: Understand the operation
Deleting a node at the end means removing the last node in the linked list.
Step 2: Identify the effect on the list
After removal, the second last node becomes the new last node.
Final Answer:
Removes the last node from the list -> Option C
Quick Check:
Delete Node at End = Remove last node [OK]
Hint: Delete last node means remove tail node [OK]
Common Mistakes:
Confusing delete at end with delete at start
Thinking it adds a node instead of removing
Assuming it deletes a middle node
2. Which of the following TypeScript code snippets correctly deletes the last node of a singly linked list named head?
easy
A. if (!head) return null;
head = head.next;
B. if (!head) return null;
let temp = head;
while (temp.next && temp.next.next) {
temp = temp.next;
}
temp.next = null;
C. let temp = head;
while (temp.next) {
temp = temp.next;
}
temp = null;
D. head = null;
Solution
Step 1: Analyze code for deleting last node
if (!head) return null;
let temp = head;
while (temp.next && temp.next.next) {
temp = temp.next;
}
temp.next = null; traverses to the second last node and sets its next to null, removing the last node.
Step 2: Check other options
if (!head) return null;
head = head.next; deletes the first node, C tries to set temp to null but does not affect list, D deletes entire list.
Final Answer:
Traverse to second last node, set next to null -> Option B
Quick Check:
Traverse to second last node, set next to null = A [OK]
Hint: Stop at second last node, set next to null [OK]
Common Mistakes:
Setting temp to null does not remove node from list
Deleting head instead of last node
Not checking for empty or single-node list
3. Given the linked list: 1 -> 2 -> 3 -> 4 -> null, what will be the list after deleting the node at the end using this code?
function deleteAtEnd(head: Node | null): Node | null {
if (!head) return null;
if (!head.next) return null;
let temp = head;
while (temp.next && temp.next.next) {
temp = temp.next;
}
temp.next = null;
return head;
}
medium
A. 2 -> 3 -> 4 -> null
B. 1 -> 2 -> 3 -> 4 -> null
C. null
D. 1 -> 2 -> 3 -> null
Solution
Step 1: Understand the code logic
The code removes the last node by stopping at second last node and setting its next to null.
Step 2: Apply to given list
Original list ends with 4. After deletion, 3's next becomes null, so list is 1 -> 2 -> 3 -> null.
Final Answer:
1 -> 2 -> 3 -> null -> Option D
Quick Check:
Last node removed, list ends at 3 [OK]
Hint: Last node removed, second last points to null [OK]
Common Mistakes:
Not updating second last node's next to null
Returning null for multi-node list
Deleting first node instead of last
4. Identify the bug in this TypeScript function that deletes the last node of a singly linked list:
function deleteAtEnd(head: Node | null): Node | null {
if (!head) return null;
let temp = head;
while (temp.next) {
temp = temp.next;
}
temp = null;
return head;
}
medium
A. It does not update the second last node's next pointer
B. It does not handle empty list
C. It deletes the head node instead of last
D. It causes infinite loop
Solution
Step 1: Analyze the loop
The loop moves temp to the last node, but does not track second last node.
Step 2: Check deletion step
Setting temp = null only changes local variable, does not remove last node from list.
Final Answer:
It does not update the second last node's next pointer -> Option A
Quick Check:
Must update second last node's next to null [OK]
Hint: Update second last node's next to null, not temp variable [OK]
Common Mistakes:
Setting temp to null does not remove node
Not tracking second last node in loop
Ignoring single-node list case
5. You have a singly linked list with nodes: 10 -> 20 -> 30 -> 40 -> null. Write a TypeScript function to delete the last node and return the updated list. Which of the following implementations correctly handles the edge case when the list has only one node?
hard
A. function deleteAtEnd(head: Node | null): Node | null {
if (!head) return null;
if (!head.next) return null;
let temp = head;
while (temp.next && temp.next.next) {
temp = temp.next;
}
temp.next = null;
return head;
}
B. function deleteAtEnd(head: Node | null): Node | null {
if (!head) return null;
let temp = head;
while (temp.next) {
temp = temp.next;
}
temp = null;
return head;
}
C. function deleteAtEnd(head: Node | null): Node | null {
if (!head) return null;
if (!head.next) return head;
let temp = head;
while (temp.next && temp.next.next) {
temp = temp.next;
}
temp.next = null;
return head;
}
D. function deleteAtEnd(head: Node | null): Node | null {
if (!head) return null;
if (!head.next) return head;
let temp = head;
while (temp.next) {
temp = temp.next;
}
temp.next = null;
return head;
}
Solution
Step 1: Check handling of single-node list
function deleteAtEnd(head: Node | null): Node | null {
if (!head) return null;
if (!head.next) return null;
let temp = head;
while (temp.next && temp.next.next) {
temp = temp.next;
}
temp.next = null;
return head;
} returns null if only one node exists, correctly deleting it.
Step 2: Verify deletion of last node for longer lists
For longer lists, it traverses to the second last node using while (temp.next && temp.next.next) and sets temp.next = null, correctly removing the last node.
Final Answer:
Correctly handles single-node by returning null -> Option A
Quick Check:
Return null for single node, else remove last node [OK]
Hint: Return null if single node, else remove last node [OK]
Common Mistakes:
Not returning null for single-node list
Setting temp to null instead of updating next pointer
Incorrect loop condition causing errors
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.