Reverse First K Elements of a Queue

Problem Reverse the order of the first k elements of a queue, leaving the remaining elements in their original relative order.

Input / Output

  • Input: queue, int k. Output: the queue rearranged in place (logically).

Constraints

  • 1 <= k <= queue size; only standard queue/stack operations allowed — no random access.

Example

  • queue = [1,2,3,4,5], k = 3 → [3,2,1,4,5].
asked …
LeaderboardSalaryAccount