Reverse First K Elements of a Queue

A FIFO queue is represented by the integer array queueValues in front-to-rear order. Reverse exactly the first k occurrences, preserve the suffix order, and…

A FIFO queue is represented by the integer array queueValues in front-to-rear order. Reverse exactly the first k occurrences, preserve the suffix order, and return the resulting front-to-rear array. Repeated values remain separate occurrences. This exercise teaches front removal, rear insertion and an auxiliary stack. The grader checks the ordered result, not the internal operations used. The array is a transport representation, not an opaque Queue object; no observable aliasing or input-mutation guarantee is required.

- 1 <= queueValues.length <= 2000. - Every value is a signed 32-bit integer. - k is an integer with 1 <= k <= queueValues.length. - Empty queues, k=0, Boolean and non-integer elements are excluded. - Return every occurrence exactly once as an ordered integer array. - Preset traces use at most 10 values and k<=6; coding retains the complete bounds above. - Teaching presets reuse the existing integer transport range -10^9 through 10^9; full int32 values remain supported by coding.

Example 1: input queueValues = [1,2,3,4,5], k = 3; output [3,2,1,4,5]. Reverse 1,2,3 while 4,5 keep their relative order.

Example 2: input queueValues = [7,7,2,7], k = 3; output [2,7,7,7]. Equal values are separate queue occurrences, not a set.

Example 3: input queueValues = [9,4], k = 1; output [9,4]. Reversing a one-element prefix leaves its order unchanged.

Category: Queues. Topic: queue. Difficulty: Easy. Patterns: stack.