Challenge - 5 Problems
Enqueue Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of enqueue operation on a queue implemented with a list
What is the output of the queue after performing the enqueue operation in the following code?
DSA Python
queue = [1, 2, 3] queue.append(4) print(queue)
Attempts:
2 left
💡 Hint
Remember that enqueue adds an element to the end of the queue.
✗ Incorrect
The append method adds the new element 4 to the end of the list representing the queue.
❓ Predict Output
intermediate2:00remaining
Output of enqueue operation on a queue implemented with collections.deque
What is the output of the queue after performing the enqueue operation in the following code?
DSA Python
from collections import deque queue = deque([10, 20, 30]) queue.append(40) print(list(queue))
Attempts:
2 left
💡 Hint
The append method of deque adds to the right end.
✗ Incorrect
The append method adds 40 to the right end of the deque, preserving order.
🔧 Debug
advanced3:00remaining
Identify the error in enqueue operation on a linked list queue
What error will the following code raise when trying to enqueue an element?
DSA Python
class Node: def __init__(self, data): self.data = data self.next = None class Queue: def __init__(self): self.front = None self.rear = None def enqueue(self, data): new_node = Node(data) if self.rear is None: self.front = new_node else: self.rear.next = new_node # Missing update of rear pointer q = Queue() q.enqueue(5) q.enqueue(10) print(q.front.data, q.rear.data)
Attempts:
2 left
💡 Hint
Check if rear pointer is updated after enqueue.
✗ Incorrect
The rear pointer is never updated after adding a new node, so rear remains None, causing AttributeError when accessing rear.data.
❓ Predict Output
advanced3:00remaining
Output of enqueue operation with circular queue array implementation
Given a circular queue of size 5 with front=3, rear=4 and elements [_, _, _, 10, 20], what is the queue state after enqueueing 30?
DSA Python
size = 5 queue = [None, None, None, 10, 20] front = 3 rear = 4 rear = (rear + 1) % size queue[rear] = 30 print(queue)
Attempts:
2 left
💡 Hint
Remember to wrap around using modulo for circular queue.
✗ Incorrect
rear moves from 4 to 0 (wrap around), so queue[0] = 30.
🧠 Conceptual
expert3:00remaining
Maximum number of elements after enqueue operations in a fixed-size circular queue
A circular queue has size 7. Initially, it is empty. After performing 5 enqueue operations and 3 dequeue operations, what is the maximum number of elements that can be in the queue?
Attempts:
2 left
💡 Hint
Think about how many elements remain after dequeues.
✗ Incorrect
After 5 enqueues, queue has 5 elements. After 3 dequeues, 2 elements are removed, so 3 remain. But maximum number after these operations can be 4 if enqueue and dequeue interleave differently.