Interleave First Half of a Queue with Second Half
Given an even-length queue represented by queueValues in front-to-rear order, return a sequence that alternates its original first and second halves, starting…
Given an even-length queue represented by queueValues in front-to-rear order, return a sequence that alternates its original first and second halves, starting with the first half. Preserve the order and multiplicity within each half. If the halves are A0...A(m-1) and B0...B(m-1), return A0,B0,A1,B1,... . Do not sort the values; any correct implementation is accepted.
n is even and 2 <= n <= 2000. Each value is a strict signed 32-bit integer, from -2147483648 through 2147483647. Return exactly n integers; the caller's input need not be mutated. Empty, singleton and odd-length inputs are outside this contract. Teaching traces use at most 20 values in [-1000000000,1000000000]; coding retains the full bounds.
Example 1: input queueValues = [1,2,3,4,5,6]; output [1,4,2,5,3,6]. The original halves [1,2,3] and [4,5,6] contribute one value at a time.
Example 2: input queueValues = [7,7,2,7]; output [7,2,7,7]. Equal values remain separate original occurrences; the first 7 pairs with 2.
Category: Queues. Topic: queue. Difficulty: Medium. Patterns: linear-scan.