Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare the struct for a linked list node.
DSA Go
type ListNode struct {
Val int
[1] *ListNode
}Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Prev' which is for doubly linked lists.
Using 'Head' which is not a node field.
Using 'Child' which is unrelated here.
✗ Incorrect
The field 'Next' points to the next node in a singly linked list.
2fill in blank
mediumComplete the code to advance the pointer in the linked list.
DSA Go
for headA != nil && headB != nil { headA = headA.[1] headB = headB.Next }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Prev' which points backward.
Using 'Head' which is not a node pointer.
Using 'Child' which is unrelated.
✗ Incorrect
To move forward in the list, use the 'Next' pointer.
3fill in blank
hardFix the error in the condition to check if two nodes are the same.
DSA Go
if headA [1] headB { return headA }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which assigns instead of compares.
Using '!=' which checks for inequality.
Using '===' which is not valid in Go.
✗ Incorrect
Use '==' to compare if two pointers point to the same node.
4fill in blank
hardFill both blanks to correctly reset pointers when they reach the end.
DSA Go
if headA == nil { headA = [1] } if headB == nil { headB = [2] }
Attempts:
3 left
💡 Hint
Common Mistakes
Resetting pointers to themselves causing infinite loops.
Using wrong variables for reset.
✗ Incorrect
When a pointer reaches the end, reset it to the start of the other list to find intersection.
5fill in blank
hardFill all three blanks to complete the function that finds the intersection node.
DSA Go
func getIntersectionNode(headA, headB *ListNode) *ListNode {
a, b := headA, headB
for a != b {
if a == nil {
a = [1]
} else {
a = a.Next
}
if b == nil {
b = [2]
} else {
b = b.Next
}
}
return [3]
}Attempts:
3 left
💡 Hint
Common Mistakes
Returning 'b' instead of 'a'.
Resetting pointers incorrectly causing infinite loops.
Not returning the intersection node.
✗ Incorrect
Reset pointer 'a' to headB and 'b' to headA when they reach nil. Return 'a' which is the intersection or nil.
