Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the queue size.
DSA Go
queue := make([]int, [1])Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 size will create an empty queue with no space.
Using nil is invalid for slice initialization.
✗ Incorrect
The queue is initialized with a fixed size of 10 to hold elements.
2fill in blank
mediumComplete the code to add an element to the queue at the rear.
DSA Go
queue[rear] = [1]Attempts:
3 left
💡 Hint
Common Mistakes
Using 'front' or 'rear' instead of the actual value.
Using 'size' which is unrelated to the element.
✗ Incorrect
We insert the given value at the rear position of the queue.
3fill in blank
hardFix the error in the dequeue operation to correctly update the front index.
DSA Go
front = (front + [1]) % sizeAttempts:
3 left
💡 Hint
Common Mistakes
Adding rear instead of 1.
Adding size or 0 which does not move the front.
✗ Incorrect
We move the front index forward by 1, wrapping around using modulo.
4fill in blank
hardFill both blanks to check if the queue is full.
DSA Go
if (rear + [1]) % size == [2] { return true } else { return false }
Attempts:
3 left
💡 Hint
Common Mistakes
Checking against 0 or size instead of front.
Adding 0 or size instead of 1 to rear.
✗ Incorrect
The queue is full if the next rear position equals front.
5fill in blank
hardFill all three blanks to create a map of queue elements with their indices.
DSA Go
queueMap := map[int]int{ [1]: queue[[2]] for [3] := front; [3] != rear; [3] = ([3] + 1) % size }Attempts:
3 left
💡 Hint
Common Mistakes
Using different variables for map key and loop index.
Using 'j' which is undefined in this context.
✗ Incorrect
We use 'i' as the loop variable and map key to store elements with their indices.
