Bird
0
0
DSA Cprogramming~20 mins

Peek Front Element of Queue in DSA C - Practice Problems & Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Queue Peek Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of peeking the front element in this queue?
Consider a queue implemented using an array with front at index 0 and rear at index 3. The queue elements are [10, 20, 30, 40]. What will be the output of the peek operation?
DSA C
int queue[] = {10, 20, 30, 40};
int front = 0;
int rear = 3;
int peek = queue[front];
printf("%d\n", peek);
A30
B40
C10
D0
Attempts:
2 left
💡 Hint
The front element is the first element inserted in the queue.
Predict Output
intermediate
2:00remaining
What happens when peeking an empty queue?
Given a queue with front = -1 and rear = -1 indicating it is empty, what will happen if we try to peek the front element?
DSA C
int front = -1;
int rear = -1;
if(front == -1) {
    printf("Queue is empty\n");
} else {
    printf("%d\n", queue[front]);
}
AQueue is empty
B0
CGarbage value
DSegmentation fault
Attempts:
2 left
💡 Hint
Check the condition that indicates the queue is empty before peeking.
🔧 Debug
advanced
2:00remaining
Why does this peek function cause an error?
This peek function is intended to return the front element of a queue. Identify the error and its cause.
DSA C
int peek(int queue[], int front, int rear) {
    if(front > rear) {
        printf("Queue is empty\n");
        return -1;
    }
    return queue[rear];
}
AIncorrect empty queue condition causes runtime error
BReturns rear element instead of front element
CReturns front element correctly
DSyntax error due to missing semicolon
Attempts:
2 left
💡 Hint
Peek should return the element at the front index, not rear.
🧠 Conceptual
advanced
1:00remaining
What is the time complexity of peeking the front element in a queue?
Assuming a queue is implemented using a linked list or array, what is the time complexity of the peek operation?
AO(1)
BO(n)
CO(log n)
DO(n^2)
Attempts:
2 left
💡 Hint
Peek just returns the front element without traversal.
🚀 Application
expert
3:00remaining
After these operations, what is the front element of the queue?
A queue is initially empty. We perform enqueue(5), enqueue(10), dequeue(), enqueue(15), dequeue(), enqueue(20). What is the front element now?
DSA C
Operations:
1. enqueue(5)
2. enqueue(10)
3. dequeue()
4. enqueue(15)
5. dequeue()
6. enqueue(20)

Assume standard FIFO queue behavior.
A10
B5
C20
D15
Attempts:
2 left
💡 Hint
Track the queue state after each operation carefully.