Given an integer K and a queue of integers, the task is to reverse the order of the first K elements in the queue, while keeping the remaining elements in their original relative order.
The following standard queue operations are allowed:
enqueue(x): Adds an element x to the rear of the queue.
dequeue(): Removes an element from the front of the queue.
size(): Returns the current number of elements in the queue.
front(): Retrieves the element at the front of the queue.
Complete the given function modifyQueue(), which takes a queue and an integer K as input parameters, and returns the modified queue. The driver code will handle the printing of the queue automatically.
Topics
Companies
Articles
Examples:
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(K)
Constraints:
1 <= K <= N <= 10^5
Companies:
AmazonVisaGoldman Sachs
Topics:
Queue
Please log in to access the Submissions tab, where you can review your progress and explore code submissions from other participants.
Please log in to access the Solution tab and view detailed answers and explanations.
Please log in to access the Discussion tab and join conversations with other participants.
Access Restricted: Please Login to access the code editor and test cases.