Challenge - 5 Problems
Queue Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this C# Queue code?
Consider the following C# code using a Queue. What will be printed after all operations?
DSA C#
using System; using System.Collections.Generic; class Program { static void Main() { Queue<int> q = new Queue<int>(); q.Enqueue(10); q.Enqueue(20); q.Enqueue(30); int first = q.Dequeue(); q.Enqueue(40); Console.WriteLine(string.Join(", ", q)); } }
Attempts:
2 left
💡 Hint
Remember that Queue removes elements from the front (FIFO).
✗ Incorrect
The first element 10 is removed by Dequeue(). Then 40 is added to the end. So the queue contains 20, 30, 40.
🧠 Conceptual
intermediateWhich statement best describes the FIFO principle in a Queue?
Choose the statement that correctly explains the FIFO principle used in Queues.
Attempts:
2 left
💡 Hint
Think about a line of people waiting for service.
✗ Incorrect
FIFO means First In, First Out. The first element added is the first to be removed, so elements come out in the order they went in.
🔧 Debug
advancedWhat error does this C# Queue code produce?
Identify the error when running this code snippet:
DSA C#
using System; using System.Collections.Generic; class Program { static void Main() { Queue<int> q = new Queue<int>(); q.Enqueue(1); q.Dequeue(); q.Dequeue(); } }
Attempts:
2 left
💡 Hint
What happens if you remove from an empty queue?
✗ Incorrect
After removing the only element, the queue is empty. Calling Dequeue again causes InvalidOperationException.
🚀 Application
advancedHow many items remain in the queue after these operations?
Given this sequence of operations on a C# Queue, how many items are left?
DSA C#
Queue<string> q = new Queue<string>(); q.Enqueue("apple"); q.Enqueue("banana"); q.Enqueue("cherry"); q.Dequeue(); q.Enqueue("date"); q.Dequeue(); q.Enqueue("elderberry");
Attempts:
2 left
💡 Hint
Count how many Enqueue and Dequeue operations happened.
✗ Incorrect
5 Enqueue and 2 Dequeue operations leave 3 items in the queue.
❓ Predict Output
expertWhat is the final printed output of this C# Queue code?
Analyze the code and determine the final output printed to the console.
DSA C#
using System; using System.Collections.Generic; class Program { static void Main() { Queue<int> q = new Queue<int>(); for (int i = 1; i <= 5; i++) { q.Enqueue(i * 10); } q.Dequeue(); q.Enqueue(60); q.Dequeue(); q.Enqueue(70); Console.WriteLine(string.Join(" -> ", q) + " -> null"); } }
Attempts:
2 left
💡 Hint
Track each enqueue and dequeue step carefully.
✗ Incorrect
Initially queue: 10,20,30,40,50
After first Dequeue: 20,30,40,50
Enqueue 60: 20,30,40,50,60
Second Dequeue: 30,40,50,60
Enqueue 70: 30,40,50,60,70
