Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to move to the last node in the linked list.
DSA C#
while (current.[1] != null) { current = current.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is for doubly linked lists.
Using 'head' or 'tail' which are not node pointers.
✗ Incorrect
We use 'next' to move from one node to the next until we reach the last node where next is null.
2fill in blank
mediumComplete the code to find the second last node before deleting the last node.
DSA C#
while (current.[1].next != null) { current = current.next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking current.prev.next which is invalid in singly linked lists.
Using current.next.next directly without checking current.next.
✗ Incorrect
We check current.next.next to find the second last node, so current.next must exist.
3fill in blank
hardFix the error in setting the last node to null to delete it.
DSA C#
current.[1] = null;Attempts:
3 left
💡 Hint
Common Mistakes
Trying to set 'head' or 'tail' to null inside the node.
Using 'prev' which is not a property in singly linked lists.
✗ Incorrect
To delete the last node, set the 'next' of the second last node to null.
4fill in blank
hardFill both blanks to correctly delete the last node from the linked list.
DSA C#
if (head == null || head.[1] == null) { head = null; } else { Node current = head; while (current.[2].next != null) { current = current.next; } current.next = null; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is not available in singly linked lists.
Checking 'tail' which is not a node property.
✗ Incorrect
We check if head.next is null to see if list has one node, then traverse using current.next to find second last node.
5fill in blank
hardFill all three blanks to implement a method that deletes the last node and returns the updated head.
DSA C#
public Node DeleteLast(Node head) {
if (head == null) return null;
if (head.[1] == null) return null;
Node current = head;
while (current.[2].next != null) {
current = current.next;
}
current.[3] = null;
return head;
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'prev' which is not defined in singly linked lists.
Returning null too early without deleting properly.
✗ Incorrect
We check if head.next is null (one node), traverse using current.next, and set current.next to null to delete last node.
