| Topic | Difficulty | Companies |
|---|---|---|
| Stack and Queue | MEDIUM |
Given an integer k and queue Q of integers. Write a program to reverse the order of the first k elements of the queue. The other elements will be in the same relative order. Following standard operations are allowed on the queue:
Example 1
Input: Q = [1, 2, 3, 4, 5]
k = 5
Output: Q = [5, 4, 3, 2, 1]
Explanation: The first 5 elements of Q are reversed.
Example 2
Input: Q = [1, 2, 3, 4, 5, 6]
k = 4
Output: Q = [4, 3, 2, 1, 5, 6]
Explanation: The first 4 elements of Q are reversed.