Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the list is empty before deleting a node.
DSA C#
if (head == [1]) { return; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of null to check for empty list.
Checking head itself instead of null.
✗ Incorrect
We check if head is null to know if the list is empty before deleting.
2fill in blank
mediumComplete the code to delete the head node if it contains the target value.
DSA C#
if (head.Value == [1]) { head = head.Next; return; }
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with head instead of target.
Using null instead of target.
✗ Incorrect
We compare head's value with the target to delete the first node if it matches.
3fill in blank
hardFix the error in the while loop condition to traverse the list correctly.
DSA C#
while (current.Next != [1] && current.Next.Value != target) { current = current.Next; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using head instead of null in condition.
Comparing current.Next to target directly.
✗ Incorrect
We check current.Next != null to avoid null reference and continue traversal.
4fill in blank
hardFill both blanks to remove the node with the target value from the list.
DSA C#
if (current.Next != [1]) { current.Next = current.Next.[2]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using Previous instead of Next.
Checking against head instead of null.
✗ Incorrect
We check current.Next is not null, then link current.Next to the next node after the one to delete.
5fill in blank
hardFill all three blanks to complete the DeleteNodeByValue method.
DSA C#
public void DeleteNodeByValue(int target) {
if (head == [1]) return;
if (head.Value == target) {
head = head.[2];
return;
}
Node current = head;
while (current.Next != [3] && current.Next.Value != target) {
current = current.Next;
}
if (current.Next != null) {
current.Next = current.Next.Next;
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using head instead of null in conditions.
Using Previous instead of Next for node links.
✗ Incorrect
We check if head is null, then update head to head.Next if first node matches target, and traverse until current.Next is null or matches target.
