Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the min heap.
DSA Go
minHeap := &[1]{} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a generic name like MinHeap without defining it.
Using PriorityQueue which is not defined in this context.
✗ Incorrect
The min heap is implemented as a ListNodeHeap struct to hold nodes.
2fill in blank
mediumComplete the code to push the first node of each list into the heap.
DSA Go
for _, node := range lists { if node != nil { heap.[1](minHeap, node) } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Append which is for slices, not heap operations.
Using Add or Insert which do not exist in heap package.
✗ Incorrect
heap.Push is the standard method to add an element to the heap in Go.
3fill in blank
hardFix the error in extracting the smallest node from the heap.
DSA Go
smallest := heap.[1](minHeap).(*ListNode) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Remove without an index causes errors.
Using Extract or Top which are not defined in heap package.
✗ Incorrect
heap.Pop removes and returns the smallest element from the heap.
4fill in blank
hardFill both blanks to link nodes and push the next node into the heap.
DSA Go
current.Next = smallest if smallest.[1] != nil { heap.[2](minHeap, smallest.Next) }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Prev instead of Next to access the next node.
Using Pop instead of Push to add nodes.
✗ Incorrect
We check if smallest.Next exists, then push it into the heap.
5fill in blank
hardFill all three blanks to define the Less method for the min heap.
DSA Go
func (h ListNodeHeap) Less(i, j int) bool {
return h[i].[1] < h[j].[2]
}
func (h ListNodeHeap) [3]() int {
return len(h)
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Value instead of Val which is the correct field name.
Using Size instead of Len for the length method.
✗ Incorrect
The Less method compares node values using .Val, and Len returns the heap size.