Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the list is empty before deletion.
DSA Go
if dll.head == [1] { return }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking if head equals 0 instead of nil.
Using 'true' or 'head' which are incorrect types.
✗ Incorrect
In Go, the head pointer is nil when the list is empty, so we check if dll.head == nil.
2fill in blank
mediumComplete the code to traverse the list to find the node with the target value.
DSA Go
current := dll.head for current != [1] && current.value != value { current = current.next }
Attempts:
3 left
💡 Hint
Common Mistakes
Using dll.tail instead of nil to check end of list.
Using current instead of nil causing infinite loop.
✗ Incorrect
We traverse until current is nil (end of list) or we find the value.
3fill in blank
hardFix the error in updating the previous node's next pointer when deleting the current node.
DSA Go
if current.prev != [1] { current.prev.next = current.next }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking against dll.head instead of nil.
Using current or dll.tail which are incorrect.
✗ Incorrect
We check if current.prev is not nil before updating its next pointer.
4fill in blank
hardFill both blanks to correctly update the next node's previous pointer and handle tail update.
DSA Go
if current.next != [1] { current.next.prev = current.prev } else { dll.tail = [2] }
Attempts:
3 left
💡 Hint
Common Mistakes
Using dll.head instead of nil in first blank.
Setting tail to current.next instead of current.prev.
✗ Incorrect
If current.next is not nil, update its prev pointer; else update tail to current.prev.
5fill in blank
hardFill all three blanks to complete the DeleteByValue function in Go.
DSA Go
func (dll *DoublyLinkedList) DeleteByValue(value int) {
if dll.head == [1] {
return
}
current := dll.head
for current != [2] && current.value != value {
current = current.next
}
if current == [3] {
return
}
if current.prev != nil {
current.prev.next = current.next
} else {
dll.head = current.next
}
if current.next != nil {
current.next.prev = current.prev
} else {
dll.tail = current.prev
}
}Attempts:
3 left
💡 Hint
Common Mistakes
Using dll.tail or dll.head instead of nil for empty checks.
Not returning when value not found.
✗ Incorrect
Check if head is nil, traverse until current is nil or value found, return if not found (current == nil).
