Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add an element to the queue.
DSA Go
func (q *Queue) Enqueue(value int) {
q.items = append(q.items, [1])
}Attempts:
3 left
💡 Hint
Common Mistakes
Using the queue itself instead of the value.
Appending the wrong variable name.
✗ Incorrect
The Enqueue method adds the given value to the end of the queue's items slice using append.
2fill in blank
mediumComplete the code to initialize a new empty queue.
DSA Go
func NewQueue() *Queue {
return &Queue{items: [1]
}Attempts:
3 left
💡 Hint
Common Mistakes
Using nil which can cause runtime errors when appending.
Using make with length 1 which creates a slice with one zero element.
✗ Incorrect
An empty slice literal []int{} initializes the items slice as empty for the new queue.
3fill in blank
hardFix the error in the Enqueue method to correctly add the value.
DSA Go
func (q *Queue) Enqueue(value int) {
q.items = append(q.items, [1])
}Attempts:
3 left
💡 Hint
Common Mistakes
Appending the queue pointer instead of the value.
Using incorrect variable names.
✗ Incorrect
The append function must add the 'value' parameter to the items slice to enqueue it.
4fill in blank
hardFill both blanks to complete the Enqueue method and print the queue after adding.
DSA Go
func (q *Queue) Enqueue(value int) {
q.items = append(q.items, [1])
fmt.Println([2])
}Attempts:
3 left
💡 Hint
Common Mistakes
Printing the wrong variable.
Appending incorrect variable.
✗ Incorrect
Append the 'value' to q.items, then print q.items to show the queue state.
5fill in blank
hardFill all three blanks to enqueue a value and return the new length of the queue.
DSA Go
func (q *Queue) Enqueue(value int) int {
q.items = append(q.items, [1])
length := len([2])
return [3]
}Attempts:
3 left
💡 Hint
Common Mistakes
Returning the value instead of the length.
Using wrong variable names for length.
✗ Incorrect
Append 'value' to q.items, get length of q.items, and return length to show queue size.
